public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Iain D Sandoe <iains@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10788] Darwin : Mark the mod init/term section starts with a linker-visible sym. Date: Sun, 29 May 2022 19:09:17 +0000 (GMT) [thread overview] Message-ID: <20220529190917.434633829BE0@sourceware.org> (raw) https://gcc.gnu.org/g:3b7661d48293fa7bb4376394007bd47cfa867db2 commit r10-10788-g3b7661d48293fa7bb4376394007bd47cfa867db2 Author: Iain Sandoe <iain@sandoe.co.uk> Date: Sat Aug 29 22:05:30 2020 +0100 Darwin : Mark the mod init/term section starts with a linker-visible sym. Some newer assemblers emit section start temp symbols for mod init and term sections if there is no suitable symbol present already. The temp symbols are linker visible and therefore appear in the symbol tables. Since the temp symbol number can vary when debug is enabled, that causes compare-debug fails. The solution is to provide a stable linker-visible symbol. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk> gcc/ChangeLog: * config/darwin.c (finalize_ctors): Add a section-start linker- visible symbol. (finalize_dtors): Likewise. * config/darwin.h (MIN_LD64_INIT_TERM_START_LABELS): New. (cherry picked from commit 66526c6a1c01b6110eaeda94ecc885177c636605) Diff: --- gcc/config/darwin.c | 37 ++++++++++++++++++++++++++++++++----- gcc/config/darwin.h | 3 +++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 3ce3a04f43a..bd7ec282a20 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -108,6 +108,9 @@ static bool ld_uses_coal_sects = false; each FDE. */ static bool ld_needs_eh_markers = false; +/* Emit a section-start symbol for mod init and term sections. */ +static bool ld_init_term_start_labels = false; + /* Section names. */ section * darwin_sections[NUM_DARWIN_SECTIONS]; @@ -1843,6 +1846,11 @@ finalize_ctors () else switch_to_section (darwin_sections[constructor_section]); + /* Where needed, provide a linker-visible section-start symbol so that we + have stable output between debug and non-debug. */ + if (ld_init_term_start_labels) + fputs (MACHOPIC_INDIRECT ? "_Mod.init:\n" : "_CTOR.sect:\n", asm_out_file); + if (vec_safe_length (ctors) > 1) ctors->qsort (sort_cdtor_records); FOR_EACH_VEC_SAFE_ELT (ctors, i, elt) @@ -1863,6 +1871,11 @@ finalize_dtors () else switch_to_section (darwin_sections[destructor_section]); + /* Where needed, provide a linker-visible section-start symbol so that we + have stable output between debug and non-debug. */ + if (ld_init_term_start_labels) + fputs (MACHOPIC_INDIRECT ? "_Mod.term:\n" : "_DTOR.sect:\n", asm_out_file); + if (vec_safe_length (dtors) > 1) dtors->qsort (sort_cdtor_records); FOR_EACH_VEC_SAFE_ELT (dtors, i, elt) @@ -3223,11 +3236,25 @@ darwin_override_options (void) /* Earlier versions are not specifically accounted, until required. */ } - /* Older Darwin ld could not coalesce weak entities without them being - placed in special sections. */ - if (darwin_target_linker - && (strverscmp (darwin_target_linker, MIN_LD64_NO_COAL_SECTS) < 0)) - ld_uses_coal_sects = true; + /* Some codegen needs to account for the capabilities of the target + linker. */ + if (darwin_target_linker) + { + /* Older Darwin ld could not coalesce weak entities without them being + placed in special sections. */ + if (strverscmp (darwin_target_linker, MIN_LD64_NO_COAL_SECTS) < 0) + ld_uses_coal_sects = true; + + /* Some newer assemblers emit section start temp symbols for mod init + and term sections if there is no suitable symbol present already. + The temp symbols are linker visible and therefore appear in the + symbol tables. Since the temp symbol number can vary when debug is + enabled, that causes compare-debug fails. The solution is to provide + a stable linker-visible symbol. */ + if (strverscmp (darwin_target_linker, + MIN_LD64_INIT_TERM_START_LABELS) >= 0) + ld_init_term_start_labels = true; + } /* In principle, this should be c-family only. However, we really need to set sensible defaults for LTO as well, since the section selection stuff diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index d3ed5ca072a..050ae00db1b 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -1100,6 +1100,9 @@ extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **); needed, and there is no need for the compiler to emit them. */ #define MIN_LD64_OMIT_STUBS "62.1" +/* Emit start labels for init and term sections from this version. */ +#define MIN_LD64_INIT_TERM_START_LABELS "136.0" + /* If we have no definition for the linker version, pick the minimum version that will bootstrap the compiler. */ #ifndef LD64_VERSION
reply other threads:[~2022-05-29 19:09 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220529190917.434633829BE0@sourceware.org \ --to=iains@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).