Age | Commit message (Collapse) | Author | Files | Lines |
|
|
|
|
|
|
|
|
|
On Linux/i386, programs and shared libraries compiled with
-mtls-dialect=gnu may fail silently at run-time against glibc without
the GNU TLS run-time fix for:
https://sourceware.org/bugzilla/show_bug.cgi?id=32996
The glibc version tag, GLIBC_ABI_GNU_TLS, has been added to indicate
that glibc has the working GNU TLS run-time:
commit ed1b7a5a489ab555a27fad9c101ebe2e1c1ba881
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Mon Jul 28 12:16:11 2025 -0700
i386: Add GLIBC_ABI_GNU_TLS version [BZ #33221]
Add the --gnu-tls-tag option to x86-64 ELF linker to add the
GLIBC_ABI_GNU_TLS version dependency in output programs and shared
libraries when linking against glibc if input relocatable object files
call ___tls_get_addr. The output will fail to load and run at run-time
against glibc which doesn't define the GLIBC_ABI_GNU_TLS version.
Add the --enable-gnu-tls-tag configure option to enable --gnu-tls-tag
by default. If unspecified, linker will add the GLIBC_ABI_GNU_TLS
version dependency if input call ___tls_get_addr and libc.so defines
the GLIBC_ABI_GNU2_TLS version.
bfd/
PR ld/33287
* elf-linker-x86.h (elf_linker_x86_params): Add
gnu_tls_version_tag.
* elf32-i386.c (elf_backend_add_glibc_version_dependency): Add
GLIBC_ABI_GNU_TLS support.
* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set
has_tls_get_addr_call to 1 if ___tls_get_addr is used.
* elfxx-x86.h (elf_x86_link_hash_table): Add has_tls_get_addr_call.
ld/
PR ld/33287
* Mention --gnu-tls-tag, --no-gnu-tls-tag and --enable-gnu-tls-tag.
* config.in: Regenerated.
* configure: Likewise.
* configure.ac: Add --enable-gnu-tls-tag.
* ld.texi: Document --gnu-tls-tag and --enable-gnu-tls-tag.
* ldlex.h (option_values): Add OPTION_GNU_TLS_VERSION_TAG and
OPTION_NO_GNU_TLS_VERSION_TAG.
* emultempl/elf-i386-glibc.em (elf_i386_glibc_before_parse):
Initialize params.gnu_tls_version_tag.
(PARSE_AND_LIST_LONGOPTS_386): New.
(PARSE_AND_LIST_OPTIONS_386): Likewise.
(PARSE_AND_LIST_ARGS_CASES_386): Likewise.
(PARSE_AND_LIST_LONGOPTS): Append $PARSE_AND_LIST_LONGOPTS_386.
(PARSE_AND_LIST_OPTIONS): Append $PARSE_AND_LIST_OPTIONS_386.
(PARSE_AND_LIST_ARGS_CASES): Append
$PARSE_AND_LIST_ARGS_CASES_386.
* testsuite/ld-i386/gnu-tls-1.s: Likewise.
* testsuite/ld-i386/gnu-tls-1a.rd: Likewise.
* testsuite/ld-i386/gnu-tls-1b.rd: Likewise.
* testsuite/ld-i386/i386.exp: Run PR ld/33287 tests.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
On Linux/x86-64, programs and shared libraries created with -z mark-plt
have the GLIBC_2.36 version tag dependency since -z mark-plt uses the
r_addend field of the R_X86_64_JUMP_SLOT relocation to store the offset
of the indirect branch instruction. Glibc versions which don't have the
commit added to glibc 2.36:
commit f8587a61892cbafd98ce599131bf4f103466f084
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Fri May 20 19:21:48 2022 -0700
x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT
won't ignore the r_addend value in the R_X86_64_JUMP_SLOT relocation. If
glibc versions defines GLIBC_ABI_DT_X86_64_PLT version tag with
commit 399384e0c8193e31aea014220ccfa24300ae5938
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Thu Aug 14 07:03:20 2025 -0700
x86-64: Add GLIBC_ABI_DT_X86_64_PLT [BZ #33212]
to indicate inclusion of the commit:
commit f8587a61892cbafd98ce599131bf4f103466f084
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Fri May 20 19:21:48 2022 -0700
x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT
we can add GLIBC_ABI_DT_X86_64_PLT version tag dependency, instead of
GLIBC_2.36 version tag dependency.
PR ld/33213
* elf-bfd.h (_bfd_elf_link_add_glibc_version_dependency): Change
return type to bool.
* elf64-x86-64.c (elf_x86_64_add_glibc_version_dependency): Add
GLIBC_ABI_DT_X86_64_PLT version tag dependency, instead of,
GLIBC_2.36 version tag dependency, for -z mark-plt if libc.so
defines GLIBC_ABI_DT_X86_64_PLT version tag.
* elflink.c (_bfd_elf_link_add_glibc_version_dependency): Change
return type to bool. Return false if elf_link_add_glibc_verneed
returns false.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
On Linux/x86, programs and shared libraries compiled with
-mtls-dialect=gnu2 may fail silently at run-time against glibc without
the GNU2 TLS run-time fixes for:
https://sourceware.org/bugzilla/show_bug.cgi?id=31501
https://sourceware.org/bugzilla/show_bug.cgi?id=31372
A version tag, GLIBC_ABI_GNU2_TLS, has been added to glibc to indicate
that glibc has the working GNU2 TLS run-time. Add the --gnu2-tls-tag
option to i386/x86-64 ELF linker to add the GLIBC_ABI_GNU2_TLS version
dependency in output programs and shared libraries when linking against
glibc if input relocatable object files have R_386_TLS_DESC_CALL or
R_X86_64_TLSDESC_CALL relocation. The output will fail to load and run
at run-time against glibc which doesn't define the GLIBC_ABI_GNU2_TLS
version.
Add the --enable-gnu2-tls-tag configure option to enable --gnu2-tls-tag
by default. If unspecified, linker will add the GLIBC_ABI_GNU2_TLS
version dependency if input object files have R_386_TLS_DESC_CALL or
R_X86_64_TLSDESC_CALL relocation and libc.so defines the GLIBC_ABI_GNU2_TLS
version.
Update elf_link_add_glibc_verneed to properly add the GLIBC_2.36 version
dependency when -z mark-plt -z nopack-relative-relocs passed to x86-64
ELF linker.
bfd/
PR ld/33130
* elf-bfd.h (_bfd_elf_link_add_glibc_version_dependency): Add
a pointer to bool argument.
* elf-linker-x86.h (elf_linker_x86_params): Add
gnu2_tls_version_tag.
* elf32-i386.c (elf_i386_scan_relocs): Set has_tls_desc_call to
1 for R_386_TLS_DESC_CALL.
(elf_i386_add_glibc_version_dependency): New. Undef before
FreeBSD support.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Set has_tls_desc_call
to 1 for R_X86_64_TLSDESC_CALL.
(elf_x86_64_add_glibc_version_dependency): Add GLIBC_ABI_GNU2_TLS
version dependency if GLIBC_ABI_GNU2_TLS dependency isn't disabled
and has_tlsdesc_call isn't 0.
(elf_backend_add_glibc_version_dependency): Undef before FreeBSD
support and redefine for elf32-x86-64.
* elflink.c (elf_link_add_glibc_verneed): Changed to return bool.
Remove the pointer to elf_find_verdep_info argument. Add a
pointer to bool argument, auto_version. Return true if linked
against glibc. Otherwise return false. If the version dependency
is added, set *auto_version to true. If *auto_version is true,
add the version dependency only if libc.so defines the version.
(_bfd_elf_link_add_glibc_version_dependency): Add a pointer to
bool argument and pass it to elf_link_add_glibc_verneed.
(_bfd_elf_link_add_dt_relr_dependency): Pass NULL to
_bfd_elf_link_add_glibc_version_dependency.
* elfxx-x86.h (elf_x86_link_hash_table): Add has_tls_desc_call.
ld/
PR ld/33130
* NEWS: Mention --gnu2-tls-tag, --no-gnu2-tls-tag and
--enable-gnu2-tls-tag.
* config.in: Regenerated.
* configure: Likewise.
* configure.ac: Add --enable-gnu2-tls-tag.
* ld.texi: Document --gnu2-tls-tag/--no-gnu2-tls-tag.
* ldlex.h (option_values): Add OPTION_GNU2_TLS_VERSION_TAG and
OPTION_NO_GNU2_TLS_VERSION_TAG.
* emulparams/elf32_x86_64.sh (EXTRA_EM_FILE): Changed to
"elf-x86-64-glibc".
* emulparams/elf_i386.sh (EXTRA_EM_FILE): Set to "elf-i386-glibc".
* emulparams/elf_i386_fbsd.sh (EXTRA_EM_FILE): New. Set to
"elf-x86".
* emulparams/elf_i386_haiku.sh (EXTRA_EM_FILE): Likewise.
* emulparams/elf_x86_64.sh (EXTRA_EM_FILE): Likewise.
* emulparams/elf_x86_64_fbsd.sh (EXTRA_EM_FILE): New. Set to
"elf-x86-64".
* emulparams/elf_x86_64_haiku.sh (EXTRA_EM_FILE): Likewise.
* (EXTRA_EM_FILE): Likewise.
* (EXTRA_EM_FILE): Likewise.
* emultempl/elf-i386-glibc.em: New file.
* emultempl/elf-x86-64-glibc.em: Likewise.
* emultempl/elf-x86-64.em: Likewise.
* emultempl/elf-x86-glibc.em: Likewise.
* emultempl/elf-x86.em (elf_x86_64_before_parse): Removed.
(LDEMUL_BEFORE_PARSE): Likewise.
(elf_x86_64_before_allocation): Likewise.
(LDEMUL_BEFORE_ALLOCATION): Likewise.
* emultempl/solaris2-x86-64.em: New file.
* testsuite/ld-i386/gnu2-tls-1.s: Likewise.
* testsuite/ld-i386/gnu2-tls-1a.rd: Likewise.
* testsuite/ld-i386/gnu2-tls-1b.rd: Likewise.
* testsuite/ld-x86-64/gnu2-tls-1.s: Likewise.
* testsuite/ld-x86-64/gnu2-tls-1a.rd: Likewise.
* testsuite/ld-x86-64/gnu2-tls-1b.rd: Likewise.
* testsuite/ld-x86-64/mark-plt-2.rd: Likewise.
* testsuite/ld-x86-64/mark-plt-2.s: Likewise.
* testsuite/ld-i386/i386.exp: Run GLIBC_ABI_GNU2_TLS tests.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
Apparently the cloudabi project is dead. The cloudabi support branded
object files with ELFOSABI_CLOUDABI but other than that didn't do much.
|
|
|
|
Prune empty generic properties before discarding empty property note
section and leave processor specific properties to the backend.
bfd/
PR ld/33292
* elf-properties.c (elf_prune_empty_properties): New function.
(_bfd_elf_link_setup_gnu_properties): Call
elf_prune_empty_properties before discarding empty property note
section. Move indirect_extern_access processing before
elf_prune_empty_properties call.
ld/
PR ld/33292
* testsuite/ld-x86-64/pr33292-x32.d: New file.
* testsuite/ld-x86-64/pr33292.d: Likewise.
* testsuite/ld-x86-64/pr33292.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/33292 tests.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
I noticed that the alignment of the .text and .data sections on
Solaris/x86 doesn't match what /bin/ld does: gld uses the original i386
psABI default of 0x1000, while Solaris has moved to larger values as can
be seen both in the Oracle Solaris 11.4 Linkers and Libraries Guide,
ch. 15, Program Loading and Dynamic Linking, p. 15-6 and the system
headers (<sys/elf_{i386,amd64}.h>) that have
while the Solaris/SPARC values are already correct.
To fix this, on i386 it's sufficient to redefine ELF_MAXPAGESIZE. On
x86_64, unlike i386, ELF_COMMONPAGESIZE is hardcoded as 0x1000, the
default, so setting ELF_MAXPAGESIZE has no effect on ELF_P_ALIGN.
Setting ELF_COMMONPAGESIZE to ELF_MAXPAGESIZE, too, fixes that and
brings both target in sync. ELF_MACHINE_CODE is just set to the original
value again, so it's removed.
Tested on {i386,amd64}-pc-solaris2.11, {i686,x86_64}-pc-linux-gnu, and
amd64-pc-freebsd14.0.
2025-07-29 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
bfd:
* elf32-i386.c <elf32-i386-sol2> (ELF_MAXPAGESIZE): Redefine.
<elf32-iamcu> (ELF_MAXPAGESIZE): Restore previous value.
* elf64-x86-64.c (ELF_COMMONPAGESIZE): Define as ELF_MAXPAGESIZE.
<elf64-x86-64-sol2> (ELF_MAXPAGESIZE): Redefine
<elf32-x86-64> (ELF_MAXPAGESIZE): Restore previous value.
(ELF_MACHINE_CODE): Remove.
|
|
Minimize the BFD_SUPPORTS_PLUGINS check to make code more readable and
maintainable by:
1. Update bfd/plugin.h to define plugin functions as static inline if
BFD_SUPPORTS_PLUGINS is 0.
2. Remove BFD_SUPPORTS_PLUGINS check from all bfd and binutils files
except plugin.h and targets.c.
3. Replace the remaining BFD_SUPPORTS_PLUGINS checks with a function so
that plugin availability is checked at run time.
bfd/
* archive.c: Include plugin.h unconditionally.
(_bfd_compute_and_write_armap): Remove the BFD_SUPPORTS_PLUGINS
check.
* bfd-in.h (bfd_plugin_enabled): New.
* bfd-in2.h: Regenerated.
* elflink.c: Include plugin.h unconditionally.
(elf_link_is_defined_archive_symbol): Remove the
BFD_SUPPORTS_PLUGINS check.
* format.c: Include plugin.h unconditionally.
(bfd_set_lto_type): Remove the BFD_SUPPORTS_PLUGINS check.
(bfd_check_format_matches): Replace the BFD_SUPPORTS_PLUGINS
check with the bfd_plugin_enabled call. Replace plugin_vec
with bfd_plugin_vec. Remove the BFD_SUPPORTS_PLUGINS check.
* plugin.c (bfd_plugin_target_p): Removed.
* plugin.h (bfd_plugin_vec): New.
(bfd_plugin_target_p): Likewise.
(bfd_plugin_set_program_name): New. Static inline
function if BFD_SUPPORTS_PLUGINS is 0.
(bfd_plugin_open_input): Likewise.
(bfd_plugin_set_plugin): Likewise.
(bfd_link_plugin_object_p): Likewise.
(register_ld_plugin_object_p): Likewise.
(bfd_plugin_close_file_descriptor): Likewise.
(bfd_plugin_vec): Likewise.
(bfd_plugin_target_p): Likewise.
* xtensa-dynconfig.c (xtensa_load_config): Replace the
BFD_SUPPORTS_PLUGINS check with the bfd_plugin_enabled call.
ar/
* ar.c: Include plugin.h unconditionally.
(plugin_target): Removed.
(usage): Replace the BFD_SUPPORTS_PLUGINS check with the
bfd_plugin_enabled call.
(ranlib_usage): Likewise.
(decode_options): Likewise.
(ranlib_main): Likewise.
(main): Call bfd_plugin_set_program_name unconditionally.
* nm.c: Include plugin.h unconditionally.
(plugin_target): Removed.
(usage): Replace the BFD_SUPPORTS_PLUGINS check with the
bfd_plugin_enabled call.
(filter_symbols): Remove the BFD_SUPPORTS_PLUGINS check.
(display_rel_file): Likewise.
(main): Call bfd_plugin_set_program_name unconditionally. Replace
the BFD_SUPPORTS_PLUGINS check with the bfd_plugin_enabled call.
* objcopy.c: Include plugin.h unconditionally.
(strip_usage): Replace the BFD_SUPPORTS_PLUGINS check with the
bfd_plugin_enabled call.
(copy_archive): Remove the BFD_SUPPORTS_PLUGINS check. Replace
BFD_SUPPORTS_PLUGINS with the bfd_plugin_enabled call.
(copy_file): Likewise.
(strip_main): Likewise.
ld/
* ldfile.c: Include plugin.h unconditionally.
(ldfile_try_open_bfd): Remove the BFD_SUPPORTS_PLUGINS check.
* ldlang.c: Include plugin.h unconditionally.
(plugin_insert): Remove the BFD_SUPPORTS_PLUGINS check.
(plugin_undefs): Likewise.
(open_input_bfds): Likewise.
(lang_check): Likewise.
(lang_gc_sections): Likewise.
(find_next_input_statement): Likewise.
(lang_process): Likewise.
* ldlang.h (lang_input_statement_flags): Likewise.
* ldlex.h (option_values): Likewise.
* ldmain.c: Include plugin.h unconditionally.
(ld_cleanup): Remove the BFD_SUPPORTS_PLUGINS check.
(main): Likewise.
(add_archive_element): Likewise.
* lexsup.c: Include plugin.h unconditionally.
(ld_options): Remove the BFD_SUPPORTS_PLUGINS check.
(parse_args): Replace the BFD_SUPPORTS_PLUGINS check with the
bfd_plugin_enabled call. Remove the BFD_SUPPORTS_PLUGINS check.
(help): Append " (ignored)" to plugin options if bfd_plugin_enabled
return false.
* libdep_plugin.c: Remove the BFD_SUPPORTS_PLUGINS check.
* plugin.c: Likewise.
* testplug.c: Likewise.
* testplug2.c: Likewise.
* testplug3.c: Likewise.
* testplug4.c: Likewise.
Co-Authored-By: Alan Modra <amodra@gmail.com>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
|
|
PR 33282
|
|
Instead make bfd_check_format try the plugin target first when the
user hasn't supplied a target.
bfd/
* format.c (bfd_check_format_matches): Try for a plugin target
match first.
* targets.c (bfd_find_target): Don't specially treat "plugin".
binutils/
* ar.c (plugin_target): Delete.
(open_inarch): Don't set target of archive elements.
(replace_members): Use target rather than plugin_target when
opening replacement or additional files.
* arsup.c (plugin_target): Delete. Replace all uses with NULL.
(ar_open): Don't set element target.
* bucomm.h (set_plugin_target): Delete.
* nm.c (plugin_target): Delete.
(display_archive): Don't set element target.
(display_file): Alway use target when opening file.
* objcopy.c (copy_archive): Don't use plugin target for output
elements.
* NEWS: Mention stricter target checking.
|
|
PR 33282
|
|
|
|
An oss-fuzz testcase with a SHT_GROUP section named .debug managed to
break objcopy --compress-debug-sections. The underlying problem is
that SEC_DEBUGGING is set by section name tests, thus the SHT_GROUP
section gets compressed. The compressed section data is smaller than
the original section sh_size, and process_sht_group_entries tries to
look at sh_size worth of entries. The patch fixes this mess by simply
not setting SEC_DEBUGGING on SHT_GROUP sections.
Note that it isn't correct to restrict SEC_DEBUGGING to SHT_PROGBITS
sections, as that will break processor/os special sections for debug.
eg. SHT_MIPS_DEBUG.
* elf.c (_bfd_elf_make_section_from_shdr): Don't set
SEC_DEBUGGING on SEC_GROUP sections no matter their name.
|
|
|
|
bfd_check_format currently does not take much notice of the target
set in its abfd arg, merely checking that target first if
target_defaulted is false. As the comment says this was due to
complications with archive handling which I think was fixed in
commit f832531609d0. It should now be possible to just check the
given target, except for linker input files. This will speed checking
the target of the first file in archives, which is done in the process
of matching archive targets.
This will no doubt expose some misuse of target options, as found in
the binutils "efi app" tests.
The stricter checking also exposed some errors. Cris targets gave
"FAIL: objcopy decompress debug sections in archive (reason: unexpected output)"
"FAIL: objcopy decompress debug sections in archive with zlib-gabi (reason: unexpected output)"
without the bfd_generic_archive_p fix. cris has a default target of
cris-aout which doesn't match objects for any of the cris-elf or
cris-linux targets. The problem here was that checking the first
object file in archives didn't match but a logic error there meant
bfd_error_wrong_object_format wasn't returned as it should be. There
was also a possibility of bfd_error_wrong_object_format persisting
from one target check to the next.
bfd/
* archive.c (bfd_generic_archive_p): Correct object in archive
target test.
* format.c (bfd_check_format_matches_lto): Try to match given
target first even when target_defaulted is set. Don't try
other targets if !target_defaulted except for linker input.
Clear bfd_error before attempted target matches.
* targets.c (bfd_find_target): Set target_defaulted for
plugin target.
binutils/
* bucomm.h (set_plugin_target): Set target_defaulted.
* testsuite/binutils-all/aarch64/pei-aarch64-little.d: Don't
wrongly specify both input and output target, just specify
output.
* testsuite/binutils-all/loongarch64/pei-loongarch64.d: Likewise.
* testsuite/binutils-all/riscv/pei-riscv64.d: Likewise.
|
|
|
|
Automatically choosing "plugin" for the archive target when plugins
are enabled can result in making archives as specified by the plugin
target vec, ie. COFF style archives (also used by most ELF
binutils targets). This is wrong for aix, hpux, vms, aout, macho
and possibly other targets, if compatibility with target system
archives matters.
This patch removes archive support entirely from the plugin target.
That means an archive will never get past bfd_check_format with a
target of plugin_vec, even if it is opened using "plugin". Instead,
archives will have their elements opened using the plugin target
selected is such a way that the plugin target will be tried first in
bfd_check_format and then continue to try other targets if that fails.
The patch tries to avoid opening archives using "plugin" because that
is guaranteed to fail the first target check in bfd_check_format, but
mm.c still does so, and nested archives will also be opened using
"plugin".
The patch also fixes poor arsup.c plugin support.
bfd/
* plugin.c (plugin_vec): Remove archive support.
* configure.ac: Remove plugin archive warning, and don't disable
plugins by default on anything but aout targets.
* configure: Regenerate.
binutils/
* bucomm.h (set_plugin_target): New inline function.
* ar.c: Remove unneeded forward declarations.
(open_inarch): Don't use "plugin" if defaulting target when
opening an archive, use "plugin" when opening elements.
(replace_members): Use "plugin" when opening replacement or
additional elements.
* arsup.c: Remove unneeded forward declarations.
(plugin_target): New.
(ar_open): Don't open archives using "plugin", use it when
opening elements.
(ar_addmod): Use plugin_target.
(ar_replace): Use plugin_target when opening replacement or
additional elements.
(ar_extract): Don't bfd_openr.
* nm.c (display_archive): Open archive elements using the
"plugin" target.
|
|
|
|
Commit 3fa785190a4f ("Altered the CREATE_xxx_COFF_TARGET_VEC macro
arguments") pretty clearly screwed up the data swapping functions in the
new CREATE_BIGHDR_COFF_TARGET_VEC() macro. Since the flaw went unnoticed,
and since the correction doesn't cause any testsuite fallout, it further
seems pretty clear that all of this is entirely untested and largely
unused.
|
|
There's no reason to have the compiler materialize objects onto the
stack.
In fact we can save some space and a level of indirection (and hence
relocation entries in the final binary) by converting to an array of
char[12] or larger. Pick char[16] for easier / faster calculations.
|
|
The spec doesn't tie entity size to just SHF_MERGE and SHF_STRINGS
sections. Introduce a new "section letter" 'E' to allow recording (and
checking) of entity size even without 'M' or 'S'.
|
|
Silently zapping them is certainly wrong. When they're not replaced due
to user request, simply keeping them may not always be correct (we don't
know what such a flag means, after all), but is certainly at least
closer to having the output object still represent what the input object
had.
This introduces new binutils/ testsuite failures, but only for two
targets where most of the tests there fail anyway (amdgcn-elf and
nfp-elf), due to there not being an assembler available.
|
|
Slim LLVM IR object is a standalone file whose first 4 bytes are 'B',
'C', 0xc0, 0xde. GCC IR object is regular ELF object with sections
whose names start with .gnu.lto_.* or .gnu.debuglto_.*. GCC IR object
uses a .gnu.lto_.lto.<some_hash> section to encode the LTO bytecode
information:
struct lto_section
{
int16_t major_version;
int16_t minor_version;
unsigned char slim_object;
/* Flags is a private field that is not defined publicly. */
uint16_t flags;
};
In slim GCC IR object, the slim_object field is non-zero. Strip should
treat slim GCC/LLVM IR objects the same. Since strip won't change slim
LLVM IR objects, it should leave slim GCC IR object unchanged even when
asked to remove all IR objects:
1. Set the lto_type field to lto_slim_ir_object for slim LLVM IR object.
2. Always copy slim IR object as unknown object.
bfd/
PR binutils/33271
* format.c (bfd_set_lto_type): Set the lto_type field to
lto_slim_ir_object for slim LLVM IR object.
binutils/
PR binutils/33271
* objcopy.c (lto_sections_removed): Removed.
(copy_archive): Always copy slim IR object as unknown object.
(copy_file): Likewise.
(strip_main): Updated.
ld/
PR binutils/33271
* testsuite/ld-plugin/lto-binutils.exp: Don't check if fat IR is
available when running slim IR tests.
* testsuite/ld-plugin/strip-1a-s-all.nd: Expect full symbol list.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
|
|
Fix PR ld/33199 SEGV in _bfd_x86_elf_create_sframe_plt
Currently, the selection for sframe_plt was not being done (and simply
set to NULL) for the case when !normal_target, causing SEGV on Solaris.
Initialize sframe_plt to init_table->sframe_lazy_plt when lazy_plt is
true, and NULL otherwise. This is in line with htab->non_lazy_plt being
set to NULL for !normal_target.
bfd/
PR ld/33199
* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties):
Setup sframe_plt for !normal_target.
|
|
In a later commit I'd like to add support to GDB for including the
NT_386_TLS note in the core files that GDB creates (using 'gcore'
command).
To achieve this we need some standard boilerplate code added to bfd.
The only part of this patch which I think needs consideration is the
name I selected for the pseudo section to hold the note contents when
a core file is loaded. I chose '.reg-i386-tls'. The '.reg' prefix is
the standard used by most other pseudo sections, and the '-i386-tls'
suffix seemed to match the note name, though I added the 'i' to
'i386', instead of just using '.reg-386-tls'. I thought 'i386' seemed
clearer.
There's no test included here, but when I merge the NT_386_TLS
creation to GDB it will depend on this and act as a test. I plan to
post that work to the GDB list once this patch is merged.
|
|
Recognise ECOFF archives and reject them so that the ecoff archive
support has a chance to handle the archive. Also use memcmp rather
than startswith (strncmp) as we know the string length.
* archive.c (bfd_slurp_armap): Recognize ECOFF armap. Use memcmp
to match names, and tidy buffer sizes.
|
|
This tidies objcopy/strip handling of IR objects, in the process of
removing the unnecessary is_strip_input flag.
The first thing I noticed when looking at is_strip_input code was that
the abfd->my_archive test in bfd_check_format_matches meant that
plugins were disabled when reading archive elements. We can instead
disable plugins by setting bfd_no_plugin, so there doesn't seem to be
a need for is_strip_input in objcopy.c:copy_archive. This isn't
exactly the same, because bfd_no_plugin prevents the plugin target
recognising archive elements in the bfd_check_format_matches loop over
all targets as well as just the first !target_defaulted test. But
that turns out to be fine. IR code is handled in copy_archive as for
other unknown format files. In fact, the only need for the plugin
target when copying archives is when reading symbols for the archive
map. I've made that plain by moving the plugin target override and
commenting on why it is really needed.
So on to plain object files. Here, IR code is also copied unchanged,
so there doesn't seem a need for the plugin target there either. It
isn't quite so simple though, because the objcopy/strip code handling
object files wants to verify the format of the object file. Allowing
objcopy/strip to copy unknown format files would be a change in
behaviour (and results in mmix testsuite fails, ld-mmix/b-badfil1 and
others). However, always excluding the plugin target results in a
fail of tests added in commit c2729c37f10a. So I've enabled a plugin
format check only for files that are otherwise unrecognised, and
commented why this is done. I question the need to objcopy LLVM
bytecode files.
bfd/
* bfd.c (struct bfd<is_strip_input>): Delete.
* format.c (bfd_check_format_matches): Delete is_strip_input
special case code.
* bfd-in2.h: Regenerate.
binutils/
* objcopy.c (copy_archive): Don't set is_strip_input. Always
set bfd_plugin_no when reading elements. Enable plugins when
opening copied elements.
(check_format_object): Delete.
(copy_file): Don't enable plugin target here. Don't set
is_strip_input. Set bfd_plugin_no. Move bfd_core handling
code earlier to remove goto. Enable plugin for llvm bytecode.
Copy slim IR files as unknown objects.
|
|
|
|
|
|
Since linker never generates dynamic relocation for protected symbol in:
__attribute__((visibility("protected"))) int my_data;
int *
func (void)
{
return &my_data;
}
we should always treat protected symbols as local.
bfd/
PR ld/33260
* elfxx-x86.h (COPY_INPUT_RELOC_P): Always treat protected symbols
as local.
ld/
PR ld/33260
* testsuite/ld-i386/i386-export-class.rd: Updated.
* testsuite/ld-i386/i386-export-class.xd: Likewise.
* testsuite/ld-i386/i386.exp: Run pr33260-2.
* testsuite/ld-i386/pr33260-2.d: New file.
* testsuite/ld-i386/pr33260-2.s: Likewise.
* testsuite/ld-i386/pr33260.d: Remove "-z indirect-extern-access".
* testsuite/ld-x86-64/pr33260-x32.d: Likewise.
* testsuite/ld-x86-64/pr33260.d: Likewise.
* testsuite/ld-x86-64/pr33260-2-x32.d: New file.
* testsuite/ld-x86-64/pr33260-2.d: Likewise.
* testsuite/ld-x86-64/pr33260-2.s: Likewise.
* testsuite/ld-x86-64/x86-64-64-export-class.rd: Updated.
* testsuite/ld-x86-64/x86-64-x32-export-class.rd: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pr33260-2 and
pr33260-2-x32.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
|
|
|
|
|
|
If all external symbol accesses are indirect, we can treat protected
symbols as local since there will be no copy relocation for data and
external function pointer access will go through GOT, instead of PLT.
No PLT slot should be used for external function pointer in executable.
bfd/
PR ld/33260
* elfxx-x86.h (COPY_INPUT_RELOC_P): Treat protected symbols with
indirect external access as local.
ld/
PR ld/33260
* testsuite/ld-i386/i386.exp: Run PR ld/33260 test.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr33260.d: New file.
* testsuite/ld-i386/pr33260.s: Likewise.
* testsuite/ld-x86-64/pr33260-x32.d: Likewise.
* testsuite/ld-x86-64/pr33260.d: Likewise.
* testsuite/ld-x86-64/pr33260.s: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|
|
|
|
There's no reason to have the compiler materialize objects onto the
stack. And there's also no reason to allow comb[] and name_table[] to be
modifiable.
|
|
There's no reason for riscv_all_supported_ext[] to appear in libbfd.so's
dynamic symbol table. There's also no reason for various pieces of data
to live in .data, when .data.rel.ro or even .rodata can do.
|
|
... and const. There's no reason to have the compiler copy anonymous
objects onto the stack. And there's also no reason to allow the arrays
to be modifiable.
|
|
|
|
It isn't needed anywhere except plugin.c. The typedef can disappear.
Also make a forward declaraion for ld_plugin_input_file in plugin.h
so that this header can be used without first including plugin-api.h.
bfd/
* plugin.h (struct ld_plugin_input_file): Forward declare.
(struct plugin_data_struct): Move to..
* plugin.c: ..here.
(add_symbols): Size plugin_data without using type.
* archive.c: Don't include plugin-api.h.
* elflink.c: Likewise.
* format.c: Likewise.
binutils/
* ar.c: Don't include plugin-api.h or ansidecl.h. Only
include plugin.h when BFD_SUPPORTS_PLUGINS.
* nm.c: Don't include plugin-api.h. Only include plugin.h
when BFD_SUPPORTS_PLUGINS.
* objcopy.c: Likewise.
ld/
* ldfile.c: Don't include plugin-api.h.
* ldmain.c: Likewise.
|
|
bfd/
* bfd.m4: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
binutils/
* configure.ac: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
gas/
* acinclude.m4: Replace AC_TRY_LINK with AC_LINK_IFELSE.
Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
gprof/
* configure.ac: Replace AC_OUTPUT(file list) with
AC_CONFIG_FILES([file list])\nAC_OUTPUT.
libctf/
* configure.ac: Replace AC_TRY_LINK with AC_LINK_IFELSE.
opcodes/
* configure.ac: Replace AC_TRY_COMPILE with AC_COMPILE_IFELSE.
|
|
There's a logic error in loongarch_relax_perform_deletes: when there's
not any delete operation of which the start address is strictly smaller
than the symbol address, splay_tree_predecessor() will return nullptr
and the symbol size will be unchanged even if some bytes of it are
removed.
Make the logic more complete to fix this issue. Also factor out the
symbol size adjustment logic into a function to avoid code bloating.
Tested-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
|
|
|
|
Fat IR objects contains both regular sections and IR sections. After
commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Sun May 4 05:12:46 2025 +0800
strip: Add GCC LTO IR support
"strip --strip-debug" no longer strips debug sections in fat IR objects
since fat IR objects are recognized as plugin object and copied as unknown
objects. Add a is_strip_input field to bfd to indicate called from strip.
Update bfd_check_format_matches not to treat archive member nor standalone
fat IR object as IR object so that strip can remove debug and IR sections
in fat IR object. For archive member, it is copied as an unknown object
if the plugin target is in use or it is a slim IR object. For standalone
fat IR object, it is copied as non-IR object.
bfd/
PR binutils/33246
* archive.c: Include "plugin-api.h" and "plugin.h" if plugin is
enabled.
(_bfd_compute_and_write_armap): Don't complain plugin is needed
when the plugin target is in use.
* bfd-in2.h: Regenerated.
* bfd.c (bfd): Add is_strip_input.
* format.c (bfd_set_lto_type): If there is .llvm.lto section,
set LTO type to lto_fat_ir_object.
(bfd_check_format_matches): Don't set LTO type when setting
format. When called from strip, don't treat archive member nor
standalone fat IR object as an IR object.
* plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
type derived from input sections.
nm/
PR binutils/33246
* nm.c (filter_symbols): Don't complain plugin is needed when
the plugin target is in use.
(display_rel_file): Likewise.
* objcopy.c (copy_archive): Set the BFD is_strip_input field of
archive member to 1 to indicate called from strip. Also copy
slim IR archive member as unknown object.
(copy_file): Set the BFD is_strip_input field of input bfd to
1 to indicate called from strip.
(strip_main): Keep .gnu.debuglto_* sections unless all GCC LTO
sections will be removed.
ld/
PR binutils/33246
* testsuite/ld-plugin/lto-binutils.exp (run_pr33246_test): New.
Run binutils/33246 tests with GCC and Clang.
* testsuite/ld-plugin/pr33246.c: New file.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
|