diff options
author | Nick Clifton <nickc@redhat.com> | 2023-03-15 14:27:21 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2023-03-15 14:27:21 +0000 |
commit | 2d5783fad77c2cb9cdcb396d65fe0a60e3d8938b (patch) | |
tree | 6f498d98b1bd86aba1498861443099802ac0f8c8 /ld/ldlang.c | |
parent | 71f646f2b3fc6e273fd17b5fdc9ba6bae242b330 (diff) | |
download | binutils-2d5783fad77c2cb9cdcb396d65fe0a60e3d8938b.zip binutils-2d5783fad77c2cb9cdcb396d65fe0a60e3d8938b.tar.gz binutils-2d5783fad77c2cb9cdcb396d65fe0a60e3d8938b.tar.bz2 |
Add --enable-linker-version option to bfd linker to add an entry in the .comment section.
PR 30187
* NEWS: Mention the new feature. * ld.texi: Document the new feature. * ldgram.y: Handle LINKER_VERSION token. * ldlang.c (lang_add_version): New function. (enable_linker_version): New global variable. * ldlang.h (land_add_version): Prototype. (enable_linker_version): Export. * ldlex.h (OPTION_ENABLE_LINKER_VERSION): Define. (OPTION_DISABLE_LINKER_VERSION): Define. * ldlex.l (LINKER_VERSION): Add token. * lexsup.c (ld_options): Add --enable-linker-version and --disable-linker-version. (parse_args): Handle the new options. * scripttempl/arclinux.sc: Remove stabs and comment sections and replace with inclusion of misc-sections.sc * scripttempl/avr.sc: Likewise. * scripttempl/dlx.sc: Likewise. * scripttempl/elf.sc: Likewise. * scripttempl/elf32cr16.sc: Likewise. * scripttempl/elf32crx.sc: Likewise. * scripttempl/elf32msp430.sc: Likewise. * scripttempl/elf64bpf.sc: Likewise. * scripttempl/elf64hppa.sc: Likewise. * scripttempl/elf_chaos.sc: Likewise. * scripttempl/elfarc.sc: Likewise. * scripttempl/elfarcv2.sc: Likewise. * scripttempl/elfd10v.sc: Likewise. * scripttempl/elfd30v.sc: Likewise. * scripttempl/elfm68hc11.sc: Likewise. * scripttempl/elfm68hc12.sc: Likewise. * scripttempl/elfm9s12z.sc: Likewise. * scripttempl/elfmicroblaze.sc: Likewise. * scripttempl/elfxgate.sc: Likewise. * scripttempl/elfxtensa.sc: Likewise. * scripttempl/epiphany_4x4.sc: Likewise. * scripttempl/ft32.sc: Likewise. * scripttempl/ip2k.sc: Likewise. * scripttempl/iq2000.sc: Likewise. * scripttempl/mep.sc: Likewise. * scripttempl/nds32elf.sc: Likewise. * scripttempl/pru.sc: Likewise. * scripttempl/v850.sc: Likewise. * scripttempl/v850_rh850.sc: Likewise. * scripttempl/visium.sc: Likewise. * scripttempl/xstormy16.sc: Likewise. * scripttempl/z80.sc: Likewise. * testsuite/ld-scripts/script.exp: Run new tests. * scripttempl/misc-sections.sc: New file. * testsuite/ld-scripts/ld-version-2.d: New file. * testsuite/ld-scripts/ld-version.d: New file. * testsuite/ld-scripts/ld-version.t: New file.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r-- | ld/ldlang.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c index 61de638..b684e2d 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -27,7 +27,6 @@ #include "obstack.h" #include "bfdlink.h" #include "ctf-api.h" - #include "ld.h" #include "ldmain.h" #include "ldexp.h" @@ -42,9 +41,11 @@ #include "demangle.h" #include "hashtab.h" #include "elf-bfd.h" +#include "bfdver.h" + #if BFD_SUPPORTS_PLUGINS #include "plugin.h" -#endif /* BFD_SUPPORTS_PLUGINS */ +#endif #ifndef offsetof #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER)) @@ -131,6 +132,7 @@ bool lang_has_input_file = false; bool had_output_filename = false; bool lang_float_flag = false; bool delete_output_file_on_failure = false; +bool enable_linker_version = false; struct lang_phdr *lang_phdr_list; struct lang_nocrossrefs *nocrossref_list; struct asneeded_minfo **asneeded_list_tail; @@ -8261,6 +8263,28 @@ lang_process (void) lang_end (); } +void +lang_add_version_string (void) +{ + if (! enable_linker_version) + return; + + const char * str = "GNU ld "; + int len = strlen (str); + int i; + + for (i = 0 ; i < len ; i++) + lang_add_data (BYTE, exp_intop (str[i])); + + str = BFD_VERSION_STRING; + len = strlen (str); + + for (i = 0 ; i < len ; i++) + lang_add_data (BYTE, exp_intop (str[i])); + + lang_add_data (BYTE, exp_intop ('\0')); +} + /* EXPORTED TO YACC */ void |