aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
2025-01-27s390: Add basic PLT generation testsJens Remus9-0/+316
ld/testsuite/ * ld-s390/plt_31_non-pic-1.pd: New non-PIC/PIE PLT generation test for 31-bit. * ld-s390/plt_31_pic-1.pd: New PIC/PIE PLT generation test for 31-bit. * ld-s390/plt_31-1.wf: New PLT generation test for 31-bit. * ld-s390/plt_64-1.pd: New PLT generation test for 64-bit. * ld-s390/plt_64-1.wf: Likewise. * ld-s390/plt-1.s: New PLT generation test for 31/64-bit. * ld-s390/pltlib.s: Likewise. * ld-s390/s390.exp: Run new PLT generation tests. Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-01-27s390: Fix linker s390 emulation option parsingJens Remus1-3/+3
Append s390-specific emulation options to the shell variables instead of replacing their contents. ld/ * emultempl/s390.em (PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS, PARSE_AND_LIST_ARGS_CASES): Append to emulation options instead of replacing them. Fixes: b4cbbe8f7294 ("S/390: Add support for pgste marker") Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-01-27Fix some broken links in docs and commentsYury Khrustalev1-3/+3
Reviewed-By Richard Earnshaw <richard.earnshaw@arm.com>
2025-01-27Exclude libpthread from automatic export generationChristopher Wellons1-0/+2
Before this change, static linking libwinpthread, commonly distributed as part of Mingw-w64, while using automatic symbol exports would export the entire threading API, which is never wanted. This is always the case when static linking libstdc++ built against libpthread.
2025-01-26ld-x86-64/pr19609-2d.d: Move "#pass" to the endH.J. Lu1-1/+1
* testsuite/ld-x86-64/pr19609-2d.d: Move "#pass" to the end. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-24x86-64: tighten convert-load-reloc checkingJan Beulich3-0/+37
Even if the assembler avoids using relaxable relocations for inapplicable insns, such relocations can still appear for other reasons. Be more thorough in the opcode checking we do, to avoid bogusly altering other insns. Furthermore correct an opcode mask (even if with the added condition that's now fully benign).
2025-01-24x86/APX: widen @gotpcrel and @gottpoff support (incl to MOVRS)Jan Beulich13-185/+486
If legacy-encoded arithmetic insns are eligible for @gotpcrel relaxation, EVEX-encoded ones ought to be, too. Further anything that MOV-from-memory can be used for (and transformed from) should then also extend to MOVRS. While extending the apx-load* testcases add -mrelax-relocations=yes to the two ones which were missing this: Without this option the intended testing would not occur on configurations defaulting the option to off.
2025-01-23ld: fix alignment issue for ARM thumb long branch stub using PureCode sectionTorbjörn SVENSSON4-1/+57
When pure-code option is activated. The linker creates for M-profile architecures a 2-bytes branch instruction. This causes the section alignment to be set to 2-byte alignment instead of 4-byte alignment. This is a problem for long branch stub without pure-code section as it contains a 32-bit address as data, which is expected to be 4-byte aligned. Hence creating a long branch stub for PureCode section followed by a long branch stub will result in a misalignment for the 32-bit address. An easy fix is to add a nop instruction after the branch to keep the section alignment to 4 bytes. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Co-authored-by: Guillaume VACHERIAS <guillaume.vacherias@st.com>
2025-01-23ld plugin.c concat leaksAlan Modra3-38/+74
* ldlang.c: Whitespace. (stat_free, stat_concat): New functions. * ldlang.h (stat_free, stat_concat): Declare. * plugin.c (asymbol_from_plugin_symbol): Use stat_concat.
2025-01-23Another ldelf_before_allocation leakAlan Modra1-8/+6
This fixes an even more obvious leak. * ldelf.c (ldelf_before_allocation): Free copied elf_dt_audit. Simplify loop.
2025-01-23More ld testsuite fixesAlan Modra2-466/+459
* testsuite/ld-elf/indirect.exp: Run compiler capability checks using run_host_noleak. * testsuite/ld-ifunc/ifunc.exp: Don't exit without restoring ASFLAGS. Don't run ifuncmod5 twice.
2025-01-23ld: fix bashism in scripttempl/elf.scSam James1-1/+1
ld/ PR ld/32580 * scripttempl/elf.sc: Fix '==' bashism.
2025-01-22ld: replace another @progbits etc in an ELF testcaseJan Beulich1-5/+5
The canonical form (in the testsuite) is %progbits and alike.
2025-01-21More updated translationsNick Clifton1-1804/+2006
2025-01-21asan ld builds without detect_leaks=0Alan Modra2-12/+28
I found that building binutils with -fsanitize=address,undefined results in much of the testsuite not being run. The problem is that running gcc results in linker plugin memory leaks which of course are errors, so the testsuite sees this as lack of compiler support. * testsuite/lib/ld-lib.exp (run_host_noleak): New proc. (check_compiler_available, check_lto_available), (check_lto_fat_available, check_lto_shared_available), (check_ifunc_available, check_ifunc_attribute_available), (check_libdl_available, check_gnu2_tls_available), (compile_one_cc): Use run_host_noleak. * testsuite/config/default.exp (compiler_supports): Likewise.
2025-01-20LD: Remove duplicate 2.44 NEWS markerMaciej W. Rozycki1-2/+0
Delete an extra 2.44 NEWS marker that has crept in by chance.
2025-01-20Update translations for various sub-directoriesNick Clifton3-6212/+7659
2025-01-20gas/NEWS,ld/NEWS: Announce LoongArch changes in 2.44Lulu Cai1-0/+2
2025-01-20ldelf_before_allocation leakAlan Modra3-5/+5
ldelf_before_allocation is passed the audit and depaudit strings built from command line args, then possibly adds to the depaudit string, freeing the original. The new string isn't freed. Fix this leak by keeping the string attached to the static vars. * ldelf.c (ldelf_before_allocation): Pass char** for audit and depaudit. Adjust uses. * ldelf.h (ldelf_before_allocation): Update prototype. * gld${EMULATION_NAME}_before_allocation: Update call.
2025-01-20sec->alloced and freeing section contentsAlan Modra1-0/+1
This modifies _bfd_elf_free_cached_info to unmap/free section contents. To do that we need to *not* free sections where contents are bfd_alloc'd or point to constant strings or somesuch. I've chosen to implement this be adding another flag to struct bfd_section, "alloced" to say the section contents can't be freed. Most of the patch is about setting that flag in many places.
2025-01-20Replace xmalloc with stat_alloc in ld parserAlan Modra7-104/+74
A few place dealing with ld script handling made some attempt to free memory, but this was generally ignored and would be quite a lot of work to implement. Instead, use the stat_obstack rather than mallocing in many more cases. * ldexp.c (exp_get_fill): Use stat_alloc for fill. * ldfile.c (ldfile_try_open_bfd): Don't free yylval fields. * ldgram.y: Replace xmalloc with stat_alloc throughout. * ldlang.c (stat_memdup, stat_strdup): New functions. (ldirname): Use stat_memdup. Don't strdup ".". (output_section_callback_sort): Use stat_alloc. (output_section_callback_tree_to_list): Don't free. (lang_memory_region_lookup): Use stat_strdup. (lang_memory_region_alias): Likewise. (add_excluded_libs): Use stat_alloc and stat_memdup. (ldlang_add_undef, ldlang_add_require_defined): Use stat_strdup. (lang_add_nocrossref, lang_leave_overlay): Use stat_alloc. (realsymbol): Use stat_strdup for return value and always free symbol. (lang_new_vers_pattern, lang_new_vers_node): Use stat_alloc. (lang_finalize_version_expr_head): Don't free. Delete FIXME. (lang_register_vers_node): Don't free. (lang_add_vers_depend): Use stat_alloc. (lang_do_version_exports_section): Likewise. (lang_add_unique): Use stat_alloc and stat_strdup. (lang_append_dynamic_list): Use stat_alloc. * ldlang.h (stat_memdup, stat_strdup): Declare. * ldlex.l: Replace xstrdup with stat_strdup throughout. Replace xmemdup with stat_memdup too. * lexsup.c (parse_args): Don't free export list or dynamic list.
2025-01-20Use stat_alloc in pluginAlan Modra1-1/+1
We never free the tv array. * plugin.c (plugin_load_plugins): Use stat_alloc.
2025-01-19Change version to 2.44.50 and regenerate filesNick Clifton2-1814/+2043
2025-01-19Add markers for bihnutils 2.44 branchNick Clifton2-0/+6
2025-01-17LoongArch: Allocate GOT entry for TLS DESC when -mno-relax is enabledLulu Cai5-0/+47
The type transition of TLSDESC is only done when -mrelax is enabled. So when -mno-relax is enabled, keep GOT_TLS_GDESC to allocate the GOT entry instead of just keeping GOT_TLS_IE.
2025-01-17cmdline_add_object_only_section leakAlan Modra1-7/+7
Free ofilename on error path. Don't bother testing "if (foo)" before "free (foo)".
2025-01-17buffer overflow in cmdline_add_object_only_sectionAlan Modra1-1/+1
Seen running ld-plugin/lto-4r-c on x86_64-w64-mingw32 * ldlang.c (cmdline_add_object_only_section): Allocate one more for output symbol buffer.
2025-01-17ld: Load the object only section when opening the mixed object fileH.J. Lu3-49/+74
Load the object only section when opening the mixed object file, instead of loading it after all other input files have been loaded. This fixed .../ld/collect-ld: /tmp/ccZAoUIW.obj-only.o: in function `main': .../ld/testsuite/ld-plugin/lto-10a.c:4: multiple definition of `main'; /usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o):(.text.startup+0x0): first defined here .../ld/collect-ld: /usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o):(.text.startup+0xc5): undefined reference to `WinMain' collect2: error: ld returned 1 exit status ... FAIL: LTO 10 for x86_64-w64-mingw32 so that mixing LTO and non-LTO relocatable files for "ld -r" works for both ELF and non-ELF platforms. * ld.texi: Remove "On ELF platforms" from documentation of mixing LTO and non-LTO relocatable files for "ld -r". * ldlang.c (cmdline_load_object_only_section): New. (cmdline_check_object_only_section): Call it. * testsuite/ld-plugin/lto.exp: Enable mixed LTO and non-LTO relocatable output tests for all. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-17xtensa unnecessary freeAlan Modra1-1/+0
No path to "cleanup" label has internal_relocs malloc'd. * emultempl/xtensaelf.em (replace_insn_sec_with_prop_sec): Don't free internal_relocs in cleanup.
2025-01-17Re: ld parser buffer leakAlan Modra1-2/+2
Apparently reflex doesn't have yyalloc. * ldlex.l (yy_create_string_buffer): Revert last change.
2025-01-17plugin_get_ir_dummy_bfd leakAlan Modra1-6/+5
* plugin.c (plugin_get_ir_dummy_bfd): Free bfd filename.
2025-01-17ld parser buffer leakAlan Modra1-2/+3
* ldlex.l (<<EOF>>): yy_delete_buffer current. (yy_create_string_buffer): Use yyalloc.
2025-01-17write_build_id and write_package_metadata leaksAlan Modra1-18/+20
There isn't much sense in stashing contents in sec->contents after those contents have been written. * ldelf.c (write_build_id): Don't assign sec->contents. Free contents if malloc'd here. (write_package_metadata): Likewise.
2025-01-17ldelf_search_needed leakAlan Modra1-1/+4
* ldelf.c (ldelf_search_needed): Free filename before returning.
2025-01-17free ldfile search pathsAlan Modra3-7/+54
* ldfile.c (ldfile_remap_input_free): Make static, call from.. (ldfile_free): ..here. New function. (ldfile_library_path_free, ldfile_script_free), ( ldfile_arch_free): New functions. (ldfile_find_command_file): Free script_dir. Move script_search to file scope. (ldfile_open_command_file_1): Delete FIXME comment. * ldfile.h (ldfile_remap_input_free): Delete. (ldfile_free): Declare. * ldlang.c (lang_finish): Update.
2025-01-17output_section_statement leakAlan Modra1-0/+6
This frees output_section_statement data, which is currently only used by elf targets but doing so for all targets is simpler and more future proof than adding ths to ldelf_finish. (Doing it there requires moving the function to ldelfgen.c.) * ldemul.c (finish_default): Free os->data.
2025-01-17NEWS: Mention mixed LTO and non-LTO output support for ld -rH.J. Lu1-0/+2
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-15aarch64: GCS tests for linking issues with dynamic objectsMatthieu Longo18-0/+247
2025-01-15aarch64: check GCS feature in GNU properties of input dynamic objectsMatthieu Longo2-10/+54
The Guarded Control Stack (GCS) feature requires that two things: - at static link time, all the input objects of a link unit have to be compatible with GCS. - at runtime, the executable and the shared libraries which it depends on have to be compatible with GCS. Both of those criteria are checked with the GCS feature stored in the GNU property note. The previous patch, adding support for the GCS feature check in GNU note properties for input objects, ignored the input dynamic objects. Although this support was better than no check, it was still delaying the detection of compatibility issues up to the runtime linker. In order to help the developer in detecting such an incompatibility issue as early as possible, this patch adds a check for input dynamic objects lacking the GCS marking. This check can be controlled via the linker option '-z gcs-report-dynamic[=none|warning|error]'. By default, if the option is omitted, it inherits the value from '-z gcs-report'. However, the inherited value is capped to 'warning' as a user might want to only report errors in the currently built module, and not the shared dependencies. If a user also wants to error on GCS issues in the shared libraries, '-z gcs-report-dynamic=error' will have to be specified explicitly.
2025-01-15ld: Update gld${EMULATION_NAME}_place_orphan for PE/PEPH.J. Lu2-22/+42
Similar to ldelf_place_orphan, initialize hold from orig_hold at run-time in PE and PEP gld${EMULATION_NAME}_place_orphan. * emultempl/pe.em (orphan_init_done): Make it file scope. (gld${EMULATION_NAME}_finish): Set orphan_init_done to false for the object-only output. (gld${EMULATION_NAME}_place_orphan): Rename hold to orig_hold. Initialize hold from orig_hold at run-time. * emultempl/pep.em (orphan_init_done): Make it file scope. (gld${EMULATION_NAME}_finish): Set orphan_init_done to false for the object-only output. (gld${EMULATION_NAME}_place_orphan): Rename hold to orig_hold. Initialize hold from orig_hold at run-time. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-15ld: Correct ldelf_place_orphanH.J. Lu1-7/+5
Remove the extra for loop and if statement in ldelf_place_orphan. * ldelf.c (ldelf_place_orphan): Remove the extra for loop and if statement. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-15Re: elf: Add GNU_PROPERTY_MEMORY_SEAL gnu propertyAlan Modra9-40/+30
Don't run tests on targets without required support. Supply an explicit -z nomemory-seal rather then relying on the harness default, to lessen confusion for people looking at the test. Don't use numeric labels for the sake of hppa64*-hpux, and run the tests there. Remove incorrect comment about source editing. Also, xfail rather than notarget failing tests with a list of target triples so we check that the list is correct.
2025-01-15Re: ld: Add --enable-memory-seal configure optionAlan Modra1-3/+2
Commit 80dc29527ff9 accidentally removed an assignment to board_flags, resulting in tcl errors 'can't read "board_flags": no such variable' on sh4-linux-gnu. Fix that by calling [get_board_flags] in the condition rather than reinstating the removed line since it seems most configurations don't have a null STATIC_LDFLAGS. Do the same in another similar test too.
2025-01-15ld: Parse linker script only onceH.J. Lu3-40/+28
Parsing linker script twice caused FAIL: ld-plugin/lto-3r FAIL: ld-plugin/lto-5r FAIL: PR ld/19317 (2) for x86_64-w64-mingw32 with the linker error: ./ld-new:built in linker script:27 assignment to location counter invalid outside of SECTIONS ldscripts/i386pep.xr has 24 .rdata : 25 { 26 *(.rdata) 27 . = ALIGN(4); 28 /* .ctors & .dtors */ 29 /* .CRT */ 30 /* ___crt_xl_end__ is defined in the TLS Directory support code */ 31 } Remove ld_parse_linker_script to parse linker script only once. * ldlang.c (cmdline_emit_object_only_section): Don't call ld_parse_linker_script. * ldmain.c (main): Fold ld_parse_linker_script. (ld_parse_linker_script): Removed. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-15ld: Call cmdline_check_object_only_section only if plugin is enabledH.J. Lu1-1/+1
* ldmain.c (add_archive_element): Call cmdline_check_object_only_section only if BFD_SUPPORTS_PLUGINS is defined. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-14ld: regenerateSam James2-10/+9
80dc29527ff9b5179741c360418e77e5064f2b69 contained some changes from non-vanilla autoconf. Regenerate. ChangeLog: * config.in: Regenerate. * configure: Regenerate.
2025-01-14ld: Add --enable-memory-seal configure optionAdhemerval Zanella9-9/+80
Add --enable-memory-seal linker configure option to enable memory sealing (GNU_PROPERTY_MEMORY_SEAL) by default. Change-Id: I4ce4ff33657f0f09b1ceb06210b6fcaa501f1799
2025-01-14elf: Add GNU_PROPERTY_MEMORY_SEAL gnu propertyAdhemerval Zanella13-0/+155
The GNU_PROPERTY_MEMORY_SEAL gnu property is a way to mark binaries to be memory sealed by the loader, to avoid further changes of PT_LOAD segments (such as unmapping or change permission flags). This is done along with Linux kernel (the mseal syscall [1]), and C runtime supports to instruct the kernel on the correct time during program startup (for instance, after RELRO handling). This support is added along the glibc support to handle the new gnu property [2]. This is a opt-in security features, like other security hardening ones like NX-stack or RELRO. The new property is ignored if present on ET_REL objects, and only added on ET_EXEC/ET_DYN if the linker option is used. A gnu property is used instead of DT_FLAGS_1 flag to allow memory sealing to work with ET_EXEC without PT_DYNAMIC support (at least on glibc some ports still do no support static-pie). [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8be7258aad44b5e25977a98db136f677fa6f4370 [2] https://sourceware.org/pipermail/libc-alpha/2024-September/160291.html Change-Id: Id47fadabecd24be0e83cff45653f7ce9a900ecf4
2025-01-14ld: Update mixed LTO and non-LTO relocatable output testsH.J. Lu1-40/+42
Since mixed LTO and non-LTO relocatable output is only supported on ELF platforms, limit these tests to ELF targets. Since powerpc64 elfv1 defines a function symbol on its procedure descriptor, which is in a data section, rather than on the code for that function, allow both D and T for nm test on mixed object. * testsuite/ld-plugin/lto.exp: Limits mixed LTO and non-LTO relocatable output tests to ELF targets. Allow both D and T for nm test on mixed object. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-14ld: Call cmdline_check_object_only_section only if plugin is enabledH.J. Lu1-1/+1
* ldfile.c (ldfile_try_open_bfd): Call cmdline_check_object_only_section only if BFD_SUPPORTS_PLUGINS is defined. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>