From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 007013858C60 for ; Fri, 15 Oct 2021 18:48:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 007013858C60 Received: by mail-wr1-x42d.google.com with SMTP id e3so27792525wrc.11 for ; Fri, 15 Oct 2021 11:48:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:reply-to :mime-version:content-transfer-encoding; bh=iogCkCzXK7onLtcP/lAEHjmWfjljth8TPc+W6b5San8=; b=YoR4BF2HdNMeVw9iwFLVuBk9i1LnygWg5Ii7R294+MquwXEjIv2eOk/mqOR4qsLYNV aE9yUDB1fyzC4dnvCPb/eERRsJ6Bf9dm6Qj86RJDM3SayCxoAp78fG5a/BTi0lwgxDE5 ysiSPIQZExei+kSPlTstW8UYA0/ofKQMAMjYgA8ftOpYYZhMYXX9suFjq3pckryqmUl3 RIlaals83y2EWhDWLPUoW8PXVODFI2pWOngEg3MUI6JICfhdXTWgYpDo0zVCmSDTN2FF MKRC+oId4EtaycUoe5aR3KWR6oYONv5+Jgq51LZst+QJGu6O+sM81FNO5vXfGWyxuyY4 yzPg== X-Gm-Message-State: AOAM530shk0tN38Fi0J/SIrEHZU8O0V1KD5uvb+k7/UeKOfpNfr6EkhU 7Iy8bkbPjsnHM/f6ZcbmzXcE+quXIQ6t/w== X-Google-Smtp-Source: ABdhPJxI+R00bi57qc59rSG5sxn40sWnTTZe+SX+DVd0CUI02ZjVuuyzkCMrh+Ov9jQjnHyJPskDng== X-Received: by 2002:a05:6000:15c6:: with SMTP id y6mr16305716wry.210.1634323680768; Fri, 15 Oct 2021 11:48:00 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id p8sm5302133wmg.15.2021.10.15.11.48.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Oct 2021 11:48:00 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] Darwin: Revise handling of some driver opts. Date: Fri, 15 Oct 2021 19:47:54 +0100 Message-Id: <20211015184754.25293-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) Reply-To: iain@sandoe.co.uk MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Fri, 15 Oct 2021 18:48:06 -0000 Darwin has a user convenience feature where some linker options are exposed at the driver level (so one can type '-all_load' instead of '-Wl,-all_load' or '-Xlinker -all_load'). We retain this feature, but now these options are all marked as 'Driver' and we process them as early as possible so that they get allocated to the right toolchain command. There are a couple of special cases where these driver opts are used multiple times, or to control operations on more than one command (e.g. dynamiclib). These are handled specially and we then add % gcc/ChangeLog: * config/darwin-driver.c (darwin_driver_init): Revise comments, handle filelist and framework options in specs instead of code. * config/darwin.h (SUBTARGET_DRIVER_SELF_SPECS): Update to handle link specs that are really driver ones. (DARWIN_CC1_SPEC): Likewise. (CPP_SPEC): Likewise. (SYSROOT_SPEC): Append space. (LINK_SYSROOT_SPEC): Remove most driver link specs. (STANDARD_STARTFILE_PREFIX_2): Update link-related specs. (STARTFILE_SPEC): Likewise. (ASM_MMACOSX_VERSION_MIN_SPEC): Fix line wrap. (ASM_SPEC): Update driver-related specs. (ASM_FINAL_SPEC): Likewise. * config/darwin.opt: Remove now unused option aliases. * config/i386/darwin.h (EXTRA_ASM_OPTS): Ensure space after opt. (ASM_SPEC): Update driver-related specs. --- gcc/config/darwin-driver.c | 30 +--- gcc/config/darwin.h | 298 +++++++++++++++++++++++-------------- gcc/config/darwin.opt | 155 ++++--------------- gcc/config/i386/darwin.h | 9 +- 4 files changed, 228 insertions(+), 264 deletions(-) diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c index 573abae4782..a036e091c48 100644 --- a/gcc/config/darwin-driver.c +++ b/gcc/config/darwin-driver.c @@ -259,14 +259,11 @@ maybe_get_sysroot_from_sdkroot () return xstrndup (maybe_sysroot, strlen (maybe_sysroot)); } -/* Translate -filelist and -framework options in *DECODED_OPTIONS - (size *DECODED_OPTIONS_COUNT) to use -Xlinker so that they are - considered to be linker inputs in the case that no other inputs are - specified. Handling these options in DRIVER_SELF_SPECS does not - suffice because specs are too late to add linker inputs, and - handling them in LINK_SPEC does not suffice because the linker will - not be called if there are no other inputs. When native, also - default the -mmacosx-version-min flag. */ +/* Handle the deduction of m32/m64 from -arch flags and the interactions + between them (i.e. try to warn a user who thinks that they have a driver + that can produce multi-slice "FAT" outputs with more than one arch). + Default the -mmacosx-version-min flag, which requires a system call on + native hosts. */ void darwin_driver_init (unsigned int *decoded_options_count, @@ -326,23 +323,6 @@ darwin_driver_init (unsigned int *decoded_options_count, seenM64 = true; break; - case OPT_filelist: - case OPT_framework: - ++*decoded_options_count; - *decoded_options = XRESIZEVEC (struct cl_decoded_option, - *decoded_options, - *decoded_options_count); - memmove (*decoded_options + i + 2, - *decoded_options + i + 1, - ((*decoded_options_count - i - 2) - * sizeof (struct cl_decoded_option))); - generate_option (OPT_Xlinker, (*decoded_options)[i].arg, 1, - CL_DRIVER, &(*decoded_options)[i + 1]); - generate_option (OPT_Xlinker, - (*decoded_options)[i].canonical_option[0], 1, - CL_DRIVER, &(*decoded_options)[i]); - break; - case OPT_mmacosx_version_min_: seen_version_min = true; vers_string = diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 0fa1c572bc9..4aedf467c17 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -118,25 +118,164 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* True if pragma ms_struct is in effect. */ extern GTY(()) int darwin_ms_struct; -/* The majority of Darwin's special driver opts are direct access to ld flags - (to save the user typing -Wl,xxxxx or Xlinker xxxxx) but we can't process - them here, since doing so will make it appear that there are linker infiles - and the linker will invoked even when it is not necessary. +/* Darwin has a user convenience feature where some linker options are exposed + at the driver level (so one can type "-all_load" instead of "-Wl,-all_load" + or "-Xlinker -all_load"). We retain this, but now these options are all + marked as 'Driver' and we process them as early as possible so that they + get allocated to the right toolchain command. There are a couple of special + cases where these driver opts are used multiple times, or to control + operations on more than one command (e.g. dynamiclib). These are handled + specially and we then add %= 10.7 mmacosx-version-min= -no_pie) }" #define DARWIN_CC1_SPEC \ - "%{findirect-virtual-calls: -fapple-kext} % The output dylib is private to the client . arch @@ -102,7 +102,7 @@ Driver RejectNegative Separate -arch Generate output for architecture . arch_errors_fatal -Driver RejectNegative Alias(Zarch_errors_fatal) +Driver RejectNegative Mismatches between file architecture and one specified by \"-arch\" are errors instead of warnings. asm_macosx_version_min= @@ -110,15 +110,15 @@ Driver RejectNegative Joined The earliest macOS version on which this program will run (formatted for the assembler). bind_at_load -Driver RejectNegative Alias(Zbind_at_load) +Driver RejectNegative Generate an output executable that binds symbols on load, rather than lazily. bundle -Driver RejectNegative Alias(Zbundle) +Driver RejectNegative Generate a Mach-O bundle (file type MH_BUNDLE). bundle_loader -Driver RejectNegative Separate Alias(Zbundle_loader) +Driver RejectNegative Separate -bundle_loader Treat (that will be loading this bundle) as if it was one of the dynamic libraries the bundle is linked against for symbol resolution. client_name @@ -134,11 +134,12 @@ Driver RejectNegative Separate -current_version Set the current version for the library to . dead_strip -Driver RejectNegative Alias(Zdead_strip) +Driver RejectNegative Remove code and data that is unreachable from any exported symbol (including the entry point). dylib_file -Driver Separate Alias(Zdylib_file) +Driver RejectNegative Separate +-dylib_file install_name:file_name This allows linking of a dylib with \"install_name\" but to be found in a different install position \"file_name\" dylinker Driver RejectNegative @@ -149,15 +150,15 @@ Driver RejectNegative Separate -dylinker_install_name Only used for building dyld. dynamic -Driver RejectNegative Alias(Zdynamic) +Driver RejectNegative The default (and opposite of -static), implied by user mode executables, shared libraries and bundles. dynamiclib -Driver RejectNegative Alias(Zdynamiclib) +Driver RejectNegative Produce a Mach-O shared library (file type MH_DYLIB), synonym for \"-shared\". exported_symbols_list -Driver RejectNegative Separate Alias(Zexported_symbols_list) +Driver RejectNegative Separate -exported_symbols_list Export global symbols in in linked output file; any symbols not mentioned will be treated as \"hidden\". filelist @@ -169,15 +170,15 @@ Driver RejectNegative Used for generating code for some older kernel revisions. flat_namespace -Driver RejectNegative Alias(Zflat_namespace) +Driver RejectNegative Ignore the normal two-level namespace; resolve symbols in command line order and do not record which library provided the resolved symbol. force_cpusubtype_ALL -Driver RejectNegative Alias(Zforce_cpusubtype_ALL) +Driver RejectNegative For the assembler (and linker) permit any architecture sub-variant to be used without error. force_flat_namespace -Driver RejectNegative Alias(Zforce_flat_namespace) +Driver RejectNegative Set the output object such that, on loading, dyld will ignore any two-level namespace information and resolve symbols in the discovery order for loaded libs. framework @@ -201,15 +202,15 @@ Driver RejectNegative Automatically adds space for longer path names in load commands (up to MAXPATHLEN). image_base -Driver RejectNegative Separate Alias(Zimage_base) +Driver RejectNegative Separate -image_base
Specify
as the base address for a dylib or bundle. init -Driver RejectNegative Separate Alias(Zinit) +Driver RejectNegative Separate -init The symbol will be used as the first initialiser for a dylib. install_name -Driver RejectNegative Separate Alias(Zinstall_name) +Driver RejectNegative Separate -install_name Set the install name for a dylib. keep_private_externs @@ -217,19 +218,19 @@ Driver RejectNegative Usually \"private extern\" (hidden) symbols are made local when linking, this command suppresses that such that they remain exported. multi_module -Driver RejectNegative Alias(Zmulti_module) +Driver RejectNegative (Obsolete after 10.4) Multi modules are ignored at runtime since macOS 10.4. multiply_defined -Driver RejectNegative Separate Alias(Zmultiply_defined) +Driver RejectNegative Separate (Obsolete after 10.4) -multiply_defined Provided a mechanism for warning about symbols defined in multiple dylibs. multiply_defined_unused -Driver RejectNegative Separate Alias(Zmultiplydefinedunused) +Driver RejectNegative Separate (Obsolete after 10.4) -multiply_defined_unused Provided a mechanism for warning about symbols defined in the current executable also being defined in linked dylibs. no_dead_strip_inits_and_terms -Driver RejectNegative Alias(Zno_dead_strip_inits_and_terms) +Driver RejectNegative (Obsolete) Current linkers never dead-strip these items, so the option is not needed. nofixprebinding @@ -299,12 +300,12 @@ Driver RejectNegative Separate Args(3) (Obsolete) -sectorder Replaced by a more general option \"-order_file\". seg_addr_table -Driver RejectNegative Separate Alias(Zseg_addr_table) +Driver RejectNegative Separate -seg_addr_table Specify the base addresses for dynamic libraries; contains a line for each library. ; This is only usable by the ld_classic linker. seg_addr_table_filename -Driver RejectNegative Separate Alias(Zfn_seg_addr_table_filename) +Driver RejectNegative Separate (Obsolete, ld_classic only) -seg_addr_table_filename . seg1addr @@ -312,7 +313,7 @@ Driver RejectNegative Separate Synonym for \"image_base\". segaddr -Driver RejectNegative Separate Args(2) Alias(Zsegaddr) +Driver RejectNegative Separate Args(2) -segaddr
Set the base address of segment to
which must be aligned to a page boundary (currently 4kb). ; This is only usable by the ld_classic linker. @@ -329,15 +330,15 @@ Driver RejectNegative Separate Args(3) -segprot The virtual memory protections for segment have maximum and initial values and respectively. The specified values may contain \"r\", \"w\", \"x\" or \"-\" the latter meaning \"no access\". segs_read_only_addr -Driver RejectNegative Separate Alias(Zsegs_read_only_addr) +Driver RejectNegative Separate -segs_read_only_addr
Specify that
is the base address of the read-only segments of a dylib. segs_read_write_addr -Driver RejectNegative Separate Alias(Zsegs_read_write_addr) +Driver RejectNegative Separate -segs_read_write_addr
Specify that
is the base address address of the read-write segments of a dylib. single_module -Driver RejectNegative Alias(Zsingle_module) +Driver RejectNegative (Obsolete) This is the default. sub_library @@ -357,7 +358,7 @@ Driver RejectNegative Add extra information to the executable that can speed up dynamic loading (provided that dependent libraries are unchanged). umbrella -Driver RejectNegative Separate Alias(Zumbrella) +Driver RejectNegative -umbrella The specified framework will be re-exported. undefined @@ -365,11 +366,11 @@ Driver RejectNegative Separate -undefined Specify the handling for undefined symbols (default is error). unexported_symbols_list -Driver RejectNegative Separate Alias(Zunexported_symbols_list) +Driver RejectNegative Separate -unexported_symbols_list Do not export the global symbols listed in . weak_reference_mismatches -Driver RejectNegative Separate Alias(Zweak_reference_mismatches) +Driver RejectNegative Separate -weak_reference_mismatches Specifies what to do if a symbol import conflicts between file (weak in one and not in another) the default is to treat the symbol as non-weak. whatsloaded @@ -391,97 +392,3 @@ Driver RejectNegative Joined Mach Driver RejectNegative (Obsolete and unhandled by ld64, ignored) ld should produce an executable (only handled by ld_classic). - -;; These are not "real" options, but placeholders used to hide the real options -;; from generic options processing... FIXME: they can be eliminated now. - -Zall_load -Driver - -Zallowable_client -Driver Separate - -Zarch_errors_fatal -Driver - -Zbind_at_load -Driver - -Zbundle -Driver - -Zbundle_loader -Driver Separate - -Zdead_strip -Driver - -Zdylib_file -Driver Separate - -Zdynamic -Driver - -Zdynamiclib -Driver - -Zexported_symbols_list -Driver Separate - -Zfn_seg_addr_table_filename -Driver Separate - -Zflat_namespace -Driver - -Zforce_cpusubtype_ALL -Driver - -Zforce_flat_namespace -Driver - -Zimage_base -Driver Separate - -Zinit -Driver Separate - -Zinstall_name -Driver Separate - -Zmulti_module -Driver - -Zmultiply_defined -Driver Separate - -Zmultiplydefinedunused -Driver Separate - -Zno_dead_strip_inits_and_terms -Driver - -Zseg_addr_table -Driver Separate - -Zsegaddr -Driver Separate Args(2) - -Zsegs_read_only_addr -Driver Separate - -Zsegs_read_write_addr -Driver Separate - -Zsingle_module -Driver - -Zumbrella -Driver Separate - -Zunexported_symbols_list -Driver Separate - -Zweak_reference_mismatches -Driver Separate - diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h index c4a6f4dfda7..741f29aa962 100644 --- a/gcc/config/i386/darwin.h +++ b/gcc/config/i386/darwin.h @@ -128,15 +128,16 @@ along with GCC; see the file COPYING3. If not see /* This is a workaround for a tool bug: see PR100340. */ #ifdef HAVE_AS_MLLVM_X86_PAD_FOR_ALIGN -#define EXTRA_ASM_OPTS " -mllvm -x86-pad-for-align=false" +#define EXTRA_ASM_OPTS " -mllvm -x86-pad-for-align=false " #else #define EXTRA_ASM_OPTS "" #endif #undef ASM_SPEC -#define ASM_SPEC "-arch %(darwin_arch) \ - " ASM_OPTIONS " -force_cpusubtype_ALL \ - %{static}" ASM_MMACOSX_VERSION_MIN_SPEC EXTRA_ASM_OPTS +#define ASM_SPEC \ +"%{static} -arch %(darwin_arch) " \ + ASM_OPTIONS ASM_MMACOSX_VERSION_MIN_SPEC EXTRA_ASM_OPTS \ +"%{!force_cpusubtype_ALL:-force_cpusubtype_ALL} " #undef ENDFILE_SPEC #define ENDFILE_SPEC \ -- 2.24.3 (Apple Git-128)