From patchwork Sat Mar 21 14:21:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1259459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48l2s44t9Rz9sQt for ; Sun, 22 Mar 2020 01:21:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 694BF3877032; Sat, 21 Mar 2020 14:21:50 +0000 (GMT) X-Original-To: GCC-patches@gcc.gnu.org Delivered-To: GCC-patches@gcc.gnu.org Received: from smtp1.wavenetuk.net (smtp.wavenetuk.net [195.26.36.10]) by sourceware.org (Postfix) with ESMTP id 377C0385C019 for ; Sat, 21 Mar 2020 14:21:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 377C0385C019 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=iain@sandoe.co.uk Received: from [192.168.1.212] (host81-138-1-83.in-addr.btopenworld.com [81.138.1.83]) by smtp1.wavenetuk.net (Postfix) with ESMTPA id 4F8791200BC3; Sat, 21 Mar 2020 14:21:47 +0000 (GMT) From: Iain Sandoe Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] Darwin: Fix i686 bootstrap when the assembler supports GOTOFF in data. Message-Id: <7B38D7C6-7639-45F1-8BF1-AB1676EBAD9E@sandoe.co.uk> Date: Sat, 21 Mar 2020 14:21:44 +0000 To: GCC-patches@gcc.gnu.org X-Mailer: Apple Mail (2.3273) X-Spam-Status: No, score=-37.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Uros Bizjak Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, When we use an assembler that supports " .long XX@GOTOFF", the current combination of configuration parameters and conditional compilation (when building an i686-darwin compiler with mdynamic-no-pic) assume that it's OK to put jump tables in the .const section. However, when we encounter a weak function with a jump table, this produces relocations that directly access the weak symbol section from the .const section - which is deemed illegal by the linker (since that would mean that the weak symbol could not be replaced). Arguably, this is a limitation (maybe even a bug) in the linker - but it seems that we'd have to change the ABI to fix it - since it would require some annotation (maybe just using a special section for the jump tables) to tell the linker that this specific circumstance is OK because the direct access to the weak symbol can only occur from that symbol itself. The fix is to force jump tables into the text section for all X86 Darwin versions (PIC code already had this change). === The change to i386.h is just a tidy up, and I can apply the darwin.h portion independently of that to fix the problem if you’d prefer no changes at this stage. OK for master (for the i386.h part of the change)? backports to open branches (for the i386.h part of the change)? thanks Iain. gcc/ChangeLog: 2020-03-21 Iain Sandoe * config/i386/darwin.h (JUMP_TABLES_IN_TEXT_SECTION): Remove references to Darwin. * config/i386/i386.h (JUMP_TABLES_IN_TEXT_SECTION): Define this unconditionally and comment on why. diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h index 1b94cb88c98..5faa1f40089 100644 --- a/gcc/config/i386/darwin.h +++ b/gcc/config/i386/darwin.h @@ -239,6 +239,16 @@ along with GCC; see the file COPYING3. If not see #undef TARGET_ASM_OUTPUT_IDENT #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive +/* We always want jump tables in the text section: + * for PIC code, we need the subtracted symbol to be defined at + assembly-time. + * for mdynamic-no-pic, we cannot support jump tables in the .const + section for weak functions, this looks to ld64 like direct access + to the weak symbol from an anonymous atom. */ + +#undef JUMP_TABLES_IN_TEXT_SECTION +#define JUMP_TABLES_IN_TEXT_SECTION 1 + /* Darwin profiling -- call mcount. If we need a stub, then we unconditionally mark it as used. */ #undef FUNCTION_PROFILER diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index 98235f75a9e..d4255f0d678 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -2285,11 +2285,10 @@ extern int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER]; /* Under some conditions we need jump tables in the text section, because the assembler cannot handle label differences between - sections. This is the case for x86_64 on Mach-O for example. */ + sections. */ #define JUMP_TABLES_IN_TEXT_SECTION \ - (flag_pic && ((TARGET_MACHO && TARGET_64BIT) \ - || (!TARGET_64BIT && !HAVE_AS_GOTOFF_IN_DATA))) + (flag_pic && (!TARGET_64BIT && !HAVE_AS_GOTOFF_IN_DATA)) /* Switch to init or fini section via SECTION_OP, emit a call to FUNC, and switch back. For x86 we do this only to save a few bytes that