aboutsummaryrefslogtreecommitdiff
path: root/bfd
AgeCommit message (Collapse)AuthorFilesLines
2025-01-15eh-frame memory leaksAlan Modra2-6/+8
The set_loc array attached to eh-frame sec_info isn't freed, and is used in _bfd_elf_eh_frame_section_offset. Rather than finding a suitable late stage of linking past any b_e_e_f_s_o use, I decided this might as well persist until the bfd is closed. Some memory is freed in _bfd_elf_discard_section_eh_frame_hdr, but the function isn't always called, so fix that too. * elf-eh-frame.c (_bfd_elf_parse_eh_frame): bfd_alloc the set_loc array. (find_merged_cie): Use bfd_malloc rather than malloc. (_bfd_elf_discard_section_eh_frame_hdr): Move condition under which this function does anything except free memory from.. * elflink.c (bfd_elf_discard_info): ..here.
2025-01-15Automatic date update in version.inGDB Administrator1-1/+1
2025-01-14elf: Add GNU_PROPERTY_MEMORY_SEAL gnu propertyAdhemerval Zanella2-18/+70
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-14aarch64 DWARF: add new CFI directive for PAuth_LRMatthieu Longo1-0/+1
This patch adds a new CFI directive (cfi_negate_ra_state_with_pc) which set an additional bit in the RA state to inform that RA was signed with SP but also PC as an additional diversifier. RA state | Description 0b00 | Return address not signed (default if no cfi_negate_ra_state*) 0b01 | Return address signed with SP (cfi_negate_ra_state) 0b10 | Invalid state 0b11 | Return address signed with SP+PC (cfi_negate_ra_state_with_pc) Approved-by: Indu Bhagat <indu.bhagat@oracle.com> Approved-by: Jan Beulich <jbeulich@suse.com>
2025-01-14Automatic date update in version.inGDB Administrator1-1/+1
2025-01-14ld: Add LTO and none-LTO output support for ld -rH.J. Lu8-36/+328
Link with mixed IR/non-IR objects * 2 kinds of object files o non-IR object file has * non-IR sections o IR object file has * IR sections * non-IR sections * The output of "ld -r" with mixed IR/non-IR objects should work with: o Compilers/linkers with IR support. o Compilers/linkers without IR support. * Add the mixed object file which has o IR sections o non-IR sections: * Object codes from IR sections. * Object codes from non-IR object files. o Object-only section: * With section name ".gnu_object_only" and SHT_GNU_OBJECT_ONLY type on ELF: https://gitlab.com/x86-psABIs/Linux-ABI #define SHT_GNU_OBJECT_ONLY 0x6ffffff8 /* Object only */ * Contain non-IR object file. * Input is discarded after link. * Linker action: o Classify each input object file: * If there is a ".gnu_object_only" section, it is a mixed object file. * If there is a IR section, it is an IR object file. * Otherwise, it is a non-IR object file. o Relocatable non-IR link: * Prepare for an object-only output. * Prepare for a regular output. * For each mixed object file: * Add IR and non-IR sections to the regular output. * For object-only section: * Extract object only file. * Add it to the object-only output. * Discard object-only section. * For each IR object file: * Add IR and non-IR sections to the regular output. * For each non-IR object file: * Add non-IR sections to the regular output. * Add non-IR sections to the object-only output. * Final output: * If there are IR objects, non-IR objects and the object-only output isn't empty: * Put the object-only output into the object-only section. * Add the object-only section to the regular output. * Remove the object-only output. o Normal link and relocatable IR link: * Prepare for output. * IR link: * For each mixed object file: * Compile and add IR sections to the output. * Discard non-IR sections. * Object-only section: * Extract object only file. * Add it to the output. * Discard object-only section. * For each IR object file: * Compile and add IR sections to the output. * Discard non-IR sections. * For each non-IR object file: * Add non-IR sections to the output. * Non-IR link: * For each mixed object file: * Add non-IR sections to the output. * Discard IR sections and object-only section. * For each IR object file: * Add non-IR sections to the output. * Discard IR sections. * For each non-IR object file: * Add non-IR sections to the output. This is useful for Linux kernel build with LTO. bfd/ PR ld/12291 PR ld/12430 PR ld/13298 * bfd.c (bfd_lto_object_type): Add lto_mixed_object. (bfd): Add object_only_section. (bfd_group_signature): New. * elf.c (special_sections_g): Add .gnu_object_only. * format.c: Include "plugin-api.h" and "plugin.h" if BFD_SUPPORTS_PLUGINS is defined. (bfd_set_lto_type): Set type to lto_mixed_object for GNU_OBJECT_ONLY_SECTION_NAME section. (bfd_check_format_matches): Don't check the plugin target twice if the plugin target is explicitly specified. * opncls.c (bfd_extract_object_only_section): New. * plugin.c (bfd_plugin_fake_text_section): New. (bfd_plugin_fake_data_section): Likewise. (bfd_plugin_fake_bss_section): Likewise. (bfd_plugin_fake_common_section): Likewise. (bfd_plugin_get_symbols_in_object_only): Likewise. * plugin.c (add_symbols): Call bfd_plugin_get_symbols_in_object_only and count plugin_data->object_only_nsyms. (bfd_plugin_get_symtab_upper_bound): Count plugin_data->object_only_nsyms. bfd_plugin_get_symbols_in_object_only and add symbols from object only section. (bfd_plugin_canonicalize_symtab): Remove fake_section, fake_data_section, fake_bss_section and fake_common_section. Set udata.p to NULL. Use bfd_plugin_fake_text_section, bfd_plugin_fake_data_section, bfd_plugin_fake_bss_section and bfd_plugin_fake_common_section. Set udata.p to NULL. * plugin.h (plugin_data_struct): Add object_only_nsyms and object_only_syms. * section.c (GNU_OBJECT_ONLY_SECTION_NAME): New. * bfd-in2.h: Regenerated. binutils/ PR ld/12291 PR ld/12430 PR ld/13298 * objcopy.c (group_signature): Removed. (is_strip_section): Replace group_signature with bfd_group_signature. (setup_section): Likewise. * readelf.c (get_os_specific_section_type_name): Handle SHT_GNU_OBJECT_ONLY. gas/ PR ld/12291 PR ld/12430 PR ld/13298 * testsuite/gas/elf/section9.s: Add the .gnu_object_only test. * testsuite/gas/elf/section9.d: Updated. include/ PR ld/12291 PR ld/12430 PR ld/13298 * elf/common.h (SHT_GNU_OBJECT_ONLY): New. ld/ PR ld/12291 PR ld/12430 PR ld/13298 * ld.h (ld_config_type): Add emit_gnu_object_only and emitting_gnu_object_only. * ldelf.c (orphan_init_done): Make it file scope. (ldelf_place_orphan): Rename hold to orig_hold. Initialize hold from orig_hold at run-time. (ldelf_finish): New. * ldelf.h (ldelf_finish): New. * ldexp.c (ldexp_init): Take a bfd_boolean argument to supprt object-only output. (ldexp_finish): Likewise. * ldexp.h (ldexp_init): Take a bfd_boolean argument. (ldexp_finish): Likewise. * ldfile.c (ldfile_try_open_bfd): Call cmdline_check_object_only_section. * ldlang.c: Include "ldwrite.h" and elf-bfd.h. * ldlang.c (cmdline_object_only_file_list): New. (cmdline_object_only_archive_list): Likewise. (cmdline_temp_object_only_list): Likewise. (cmdline_lists_init): Likewise. (cmdline_list_new): Likewise. (cmdline_list_append): Likewise. (print_cmdline_list): Likewise. (cmdline_on_object_only_archive_list_p): Likewise. (cmdline_object_only_list_append): Likewise. (cmdline_get_object_only_input_files): Likewise. (cmdline_arg): Likewise. (setup_section): Likewise. (copy_section): Likewise. (cmdline_fopen_temp): Likewise. (cmdline_add_object_only_section): Likewise. (cmdline_emit_object_only_section): Likewise. (cmdline_extract_object_only_section): Likewise. (cmdline_check_object_only_section): Likewise. (cmdline_remove_object_only_files): Likewise. (lang_init): Take a bfd_boolean argument to supprt object-only output. Call cmdline_lists_init. (load_symbols): Call cmdline_on_object_only_archive_list_p to check if an archive member should be loaded. (lang_process): Handle object-only link. * ldlang.h (lang_init): Take a bfd_boolean argument. (cmdline_enum_type): New. (cmdline_header_type): Likewise. (cmdline_file_type): Likewise. (cmdline_bfd_type): Likewise. (cmdline_union_type): Likewise. (cmdline_list_type): Likewise. (cmdline_emit_object_only_section): Likewise. (cmdline_check_object_only_section): Likewise. (cmdline_remove_object_only_files): Likewise. * ldmain.c (main): Call xatexit with cmdline_remove_object_only_files. Pass FALSE to lang_init, ldexp_init and ldexp_finish. Use ld_parse_linker_script. Set link_info.output_bfd to NULL after close. Call cmdline_emit_object_only_section if needed. (add_archive_element): Call cmdline_check_object_only_section. (ld_parse_linker_script): New. * ldmain.h (ld_parse_linker_script): New. * plugin.c (plugin_maybe_claim): Call cmdline_check_object_only_section on claimed IR files. * scripttempl/elf.sc: Also discard .gnu_object_only sections. * scripttempl/elf64hppa.sc: Likewise. * scripttempl/elfxtensa.sc: Likewise. * scripttempl/mep.sc: Likewise. * scripttempl/pe.sc: Likewise. * scripttempl/pep.sc: Likewise. * emultempl/aarch64elf.em (gld${EMULATION_NAME}_finish): Replace finish_default with ldelf_finish. * emultempl/alphaelf.em (alpha_finish): Likewise. * emultempl/avrelf.em (avr_finish): Likewise. * emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Likewise. * emultempl/ppc32elf.em (ppc_finish): Likewise. * emultempl/ppc64elf.em (gld${EMULATION_NAME}_finish): Likewise. * emultempl/spuelf.em (gld${EMULATION_NAME}_finish): Likewise. * testsuite/ld-plugin/lto-10.out: New file. * testsuite/ld-plugin/lto-10a.c: Likewise. * testsuite/ld-plugin/lto-10b.c: Likewise. * testsuite/ld-plugin/lto-10r.d: Likewise. * testsuite/ld-plugin/lto-4.out: Likewise. * testsuite/ld-plugin/lto-4a.c: Likewise. * testsuite/ld-plugin/lto-4b.c: Likewise. * testsuite/ld-plugin/lto-4c.c: Likewise. * testsuite/ld-plugin/lto-4r-a.d: Likewise. * testsuite/ld-plugin/lto-4r-b.d: Likewise. * testsuite/ld-plugin/lto-4r-c.d: Likewise. * testsuite/ld-plugin/lto-4r-d.d: Likewise. * testsuite/ld-plugin/lto.exp (lto_link_tests): Prepare for "LTO 4[acd]", "lto-4r-[abcd]" and "LTO 10" tests. (lto_run_tests): Add "LTO 4[acd]" and "LTO 10" tests. Build liblto-4.a. Run "lto-4r-[abcd]" tests. Run lto-10r and create tmpdir/lto-10.o. Add test for nm on mixed LTO/non-LTO object. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-01-13bfd/ELF: slightly "better" file alignment for object filesJan Beulich1-1/+5
PR gas/32435 Commit 1f1b5e506bf0 ("bfd/ELF: restrict file alignment for object files") caused an issue in the Linux kernels modpost utility, which was building upon .rodata sections to be 4-byte aligned in the file when they have 4-byte alignment. While we don't want to revert back to original behavior, apply the same alignment "capping" as done originally in two other places also for "ordinary" sections.
2025-01-13RISC-V: Cleanup the imply code and test cases for vendor xsf extensions.Nelson Chu1-1/+0
2025-01-13Automatic date update in version.inGDB Administrator1-1/+1
2025-01-12Automatic date update in version.inGDB Administrator1-1/+1
2025-01-11Automatic date update in version.inGDB Administrator1-1/+1
2025-01-10Automatic date update in version.inGDB Administrator1-1/+1
2025-01-09Automatic date update in version.inGDB Administrator1-1/+1
2025-01-08Automatic date update in version.inGDB Administrator1-1/+1
2025-01-07Updated Malay translation for the bfd sub-directoryNick Clifton1-12/+7
2025-01-07Remove dead code in bfd_check_format_matchesAlan Modra1-8/+0
Commit cb001c0d283d made code added in 64bfc2584c01 dead. Remove it.
2025-01-07Automatic date update in version.inGDB Administrator1-1/+1
2025-01-06ar and foreign object filesAlan Modra8-16/+34
ar is supposed to make archives containing any sort of file, and it generally does that. It also tries to make archives suited to target object files stored. Some targets have peculiar archives. In one particular case we get into trouble trying to suit archives to object files: where the target object file is recognised but that target doesn't happen to support archives, and the default target has a special archive format. For example, we'll get failures on rs6000-aix if trying to add tekhex objects to a new archive. What happens in that the tekhex object is recognised and its target vector used to create an empty archive, ie. with _bfd_generic_mkarchive and _bfd_write_archive_contents. An attempt is then made to open the newly created archive. The tekhex target vector does not have a check_format function to recognise generic archives, nor as it happens do any of the xcoff or other targets built for rs6000-aix. It seems to me the simplest fix is to not use any target vector to create archives where that vector can't also recognise them. That's what this patch does, and to reinforce that I've removed target vector support for creating empty archives from such targets. bfd/ * i386msdos.c (i386_msdos_vec): Remove support for creating empty archives. * ihex.c (ihex_vec): Likewise. * srec.c (srec_vec, symbolsrec_vec): Likewise. * tekhex.c (tekhex_vec): Likewise. * wasm-module.c (wasm_vec): Likewise. * ptrace-core.c (core_ptrace_vec): Tidy. * targets.c (bfd_target_supports_archives): New inline function. * bfd-in2.h: Regenerate. binutils/ * ar.c (open_inarch): Don't select a target from the first object file that can't read archives. Set output_filename earlier. * testsuite/binutils-all/ar.exp (thin_archive_with_nested): Don't repeat --thin test using T. (foreign_object): New test. * testsuite/binutils-all/tek1.obj, * testsuite/binutils-all/tek2.obj: New files.
2025-01-06Automatic date update in version.inGDB Administrator1-1/+1
2025-01-05Automatic date update in version.inGDB Administrator1-1/+1
2025-01-04ELF sec_info memory leaksAlan Modra2-5/+4
Use the bfd's objalloc memory so we don't need to free anything attached to elf_section_data sec_info. Other uses of sec_info that need to allocate memory already use bfd_alloc. * elf-eh-frame.c (_bfd_elf_parse_eh_frame): bfd_alloc sec_info. * elf-sframe.c (_bfd_elf_parse_sframe): Likewise.
2025-01-04_bfd_write_ar_hdrAlan Modra2-2/+2
This has been broken since commit 8f95b6e44955 in 2010, and apparently nobody has noticed. How we write archive headers depends on the archive, not the contents. * libbfd-in.h (_bfd_write_ar_hdr): Correct. * libbfd.h: Regenerate.
2025-01-04bfd_set_input_errorAlan Modra3-43/+18
My recent change to closing archives showed some problems with the way we stash errors for archive elements. The most obvious thing found by oss-fuzz, is that if output archive elements are closed during bfd_close of an archive, then we can't access the element filename when printing the element. So change bfd_set_input_error to stash the entire error message instead of input bfd and input error. * bfd.c (input_bfd, input_error): Delete. (bfd_error, _bfd_error_buf): Move. (_bfd_clear_error_data): Move. Make static. Clear bfd_error too. (bfd_set_input_error): Print the error use bfd_asprintf here.. (bfd_errmsg): ..not here. (bfd_init): Update. * opncls.c (bfd_close_all_done): Don't call _bfd_clear_error_data. * libbfd.h: Regenerate.
2025-01-04Automatic date update in version.inGDB Administrator1-1/+1
2025-01-03Automatic date update in version.inGDB Administrator1-1/+1
2025-01-02Automatic date update in version.inGDB Administrator1-1/+1
2025-01-01gnu_debuglink related memory leakAlan Modra1-9/+4
* opncls.c (bfd_fill_in_gnu_debuglink_section): Free section contents on success too.
2025-01-01Close elements of output archiveAlan Modra1-0/+9
When cleaning up an archive, close all its elements. This fixes a number of ar memory leaks. bfd/ * archive.c (_bfd_archive_close_and_cleanup): Close elements of an archive open for writing. binutils/ * objcopy.c (copy_archive): Don't close output archive elements here. * dlltool.c (gen_lib_file): Likewise. ld/ * pe-dll.c (pe_dll_generate_implib): Don't close output archive elements here.
2025-01-01thin archive with nested archive memory leakAlan Modra1-10/+5
The only reason to keep new_areldata around was for access to the filename, but we now always take a copy in alloc'd memory. * archive.c (_bfd_get_elt_at_filepos): Free new_areldata when it is not attached to bfd.
2025-01-01PR 32507, PRIx64 in error messages on 32-bit mingwAlan Modra1-9/+51
People, including me, had forgotten that the bfd_error_handler just handled standard printf format strings, not MSC %I64 and suchlike. Using PRIx64 and similar in errors does not work if the host compiler headers define those formats as the Microsoft %I64 variety. (We handled %ll OK, editing it to %I64 on such hosts.) PR 32507 * bfd.c (_bfd_doprnt, _bfd_doprnt_scan): Handle %I64 and %I32 in input strings if the host defines PRId64 as "I64d". Edit %ll to %I64 on detecting PRId64 as "I64d" rather than on a preprocessor define.
2025-01-01Update year range in copyright notice of binutils filesAlan Modra434-439/+439
2025-01-01Automatic date update in version.inGDB Administrator1-1/+1
2024-12-31Automatic date update in version.inGDB Administrator1-1/+1
2024-12-30Automatic date update in version.inGDB Administrator1-1/+1
2024-12-29Automatic date update in version.ingdb-16-branchpointGDB Administrator1-1/+1
2024-12-28Automatic date update in version.inGDB Administrator1-1/+1
2024-12-27bfd/ELF: refine segment index in filepos assignment diagJan Beulich1-2/+2
Reporting an internal loop index isn't helpful for the user to determine which segment the problem is with. Report the PHDR index instead.
2024-12-27LoongArch: Reword message for unresolvable relocsXi Ruoyao1-6/+17
For PDE, "recompiling with -fPIE" just makes no sense. For PIE, "recompiling with -fPIE" makes sense for unresolvable absolute relocs, but not unresolveable PC-relative relocs: if the reloc is already PC-relative, the problem is not the reloc is PC-relative or absolute, but the reloc is not applicable for external symbols. If we hit an unresolvable reloc in PDE or an unresolvable PC-relative reloc in PIE, it means the programmer has somehow wrongly instructed the compiler to treat external symbols as local symbols. A misuse of -mdirect-extern-access can cause the issue, so we can suggest -mno-direct-extern-access. And in all cases (DSO/PIE/PDE) a mismatching symbol visibility can also cause the issue, so we should also suggest to check the visibility. Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-12-27LoongArch: Allow R_LARCH_PCALA_HI20 or R_LARCH_PCREL20_S2 against undefined ↵Xi Ruoyao1-9/+18
weak symbols for static PIE In a static PIE, undefined weak symbols should be just resolved to runtime address 0, like those symbols with non-default visibility. This was silently broken in all prior Binutils releases with "-static-pie -mdirect-extern-access": $ cat t.c int x (void) __attribute__ ((weak)); int main (void) { __builtin_printf("%p\n", x); } $ gcc t.c -static-pie -mdirect-extern-access $ ./a.out 0x7ffff1d64000 Since commit 4cb77761d687 ("LoongArch: Check PC-relative relocations for shared libraries), the situation has been improved: the linker errors out instead of silently producing a wrong output file. But logically, using -mdirect-extern-access for a static PIE perfectly makes sense, and we should not prevent that even if the programmer uses weak symbols. Linux kernel is such an example, and Linux < 6.10 now fails to build with Binutils trunk. (The silent breakage with prior Binutils releases was "benign" due to some blind luck.) While since the 6.10 release Linux has removed those potentially undefined weak symbols (due to performance issue), we still should support weak symbols in -mdirect-extern-access -static-pie and unbreak building old kernels. Link: https://lore.kernel.org/loongarch/20241206085810.112341-1-chenhuacai@loongson.cn/ Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-12-27LoongArch: Fix resolution of undefined weak hidden/protected symbolsXi Ruoyao1-22/+61
An undefined weak hidden/protect symbol should be resolved to runtime address 0, but we were actually resolving it to link-time address 0. So in PIE or DSO the runtime address would be incorrect. Fix the issue by rewriting pcalau12i to lu12i.w, and pcaddi to addi.w. The latter does not always work because the immediate field of addi.w is narrower, report an error in the case the addend is too large. Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-12-27Automatic date update in version.inGDB Administrator1-1/+1
2024-12-26Automatic date update in version.inGDB Administrator1-1/+1
2024-12-25Automatic date update in version.inGDB Administrator1-1/+1
2024-12-24PR 32324, Stripping BOLT'ed binaries leads to unwanted behaviourAlan Modra1-5/+5
This patch corrects layout for a PT_LOAD header that doesn't include the ELF file header but does contain PHDRs and sections requiring alignment. The required alignment (which was missing) is placed before the PHDRs.
2024-12-24Automatic date update in version.inGDB Administrator1-1/+1
2024-12-23Automatic date update in version.inGDB Administrator1-1/+1
2024-12-22Automatic date update in version.inGDB Administrator1-1/+1
2024-12-21Automatic date update in version.inGDB Administrator1-1/+1
2024-12-20Automatic date update in version.inGDB Administrator1-1/+1
2024-12-19Updated Serbian translation for the bfd sub-directoryNick Clifton1-1413/+1508