x86/build: use --orphan-handling linker option if available
PATCH v3 1/1 x86/build: use --orphan-handling linker option if available
As was e.g. making necessary 4b7fd8153ddf ("x86: fold sections in final binaries"), arbitrary sections appearing without our linker script placing them explicitly can be a problem. Have the linker make us aware of such sections, so we would know that the script needs adjusting.
To deal with the resulting warnings:
- Retain .note.* explicitly for ELF, and discard all of them (except the earlier consumed .note.gnu.build-id) for PE/COFF.
- Have explicit statements for .got, .plt, and alike and add assertions that they're empty. No output sections will be created for these as long as they remain empty (or else the assertions would cause early failure anyway).
- Collect all .rela.* into a single section, with again an assertion added for the resulting section to be empty.
- Extend the enumerating of .debug_* to ELF. Note that for Clang adding of .debug_macinfo is necessary. Amend this by its Dwarf5 counterpart, .debug_macro, then as well (albeit more may need adding for full coverage).
---
v3: Extend a comment. Add comment ahead of .note.Xen.
v2: Don't use (NOLOAD) for ELF; it has undocumented (and unhelpful)
behavior with GNU ld there. Also place .{sym,str,shstr}tab for LLVM ld.
---
I would have wanted to make this generic (by putting it in xen/Makefile), but the option cannot be added to LDFLAGS, or else there'll be a flood of warnings with $(LD) -r. (Besides, adding to LDFLAGS would mean use of the option on every linker pass rather than just the last one.)
Retaining of .note in xen-syms is under question. Plus if we want to retain all notes, the question is whether they wouldn't better go into .init.rodata. But .note.gnu.build-id shouldn't move there, and when notes are discontiguous all intermediate space will also be assigned to the NOTE segment, thus making the contents useless for tools going just by program headers.
Newer Clang may require yet more .debug_* to be added. I've only played with versions 5 and 7 so far.
Unless we would finally drop all mentioning of Stabs sections, we may want to extend to there what is done for Dwarf here (allowing the EFI conditional around the section to also go away).
See also https://sourceware.org/pipermail/binutils/2022-March/119922.html.
xen/arch/x86/Makefile +4 -2
@@ -119,6 +119,8 @@ syms-warn-dup-y := --warn-dup syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup +orphan-handling-$(call ld-option,--orphan-handling=warn) += --orphan-handling=warn + $(TARGET): TMP = $(@D)/.$(@F).elf32 $(TARGET): $(TARGET)-syms $(efi-y) $(obj)/boot/mkelf32 $(obj)/boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TMP) $(XEN_IMG_OFFSET) \
@@ -145,7 +147,7 @@ $(TARGET)-syms: $(BASEDIR)/prelink.o $(o >$(@D)/.$(@F).1.S $(MAKE) $(build)=$(@D) $(@D)/.$(@F).1.o $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) \ - $(@D)/.$(@F).1.o -o $@ + $(orphan-handling-y) $(@D)/.$(@F).1.o -o $@ $(NM) -pa --format=sysv $(@D)/$(@F) \ | $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort \ >$(@D)/$(@F).map
@@ -219,7 +221,7 @@ endif | $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort >$(@D)/.$(@F).1s.S $(MAKE) $(build)=$(@D) .$(@F).1r.o .$(@F).1s.o $(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds -N $< \ - $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(note_file_option) -o $@ + $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(orphan-handling-y) $(note_file_option) -o $@ $(NM) -pa --format=sysv $(@D)/$(@F) \ | $(BASEDIR)/tools/symbols --all-symbols --xensyms --sysv --sort >$(@D)/$(@F).map rm -f $(@D)/.$(@F).[0-9]* $(@D)/..$(@F).[0-9]*
xen/arch/x86/xen.lds.S +101 -67
228 lines not on this page · raw message
Quoted 5 lines · Jan Beulich
As was e.g. making necessary
4b7fd8153ddf("x86: fold sections in final binaries"), arbitrary sections appearing without our linker script placing them explicitly can be a problem. Have the linker make us aware of such sections, so we would know that the script needs adjusting.
Quoted 13 lines
To deal with the resulting warnings:
- Retain .note.* explicitly for ELF, and discard all of them (except the earlier consumed .note.gnu.build-id) for PE/COFF.
- Have explicit statements for .got, .plt, and alike and add assertions that they're empty. No output sections will be created for these as long as they remain empty (or else the assertions would cause early failure anyway).
- Collect all .rela.* into a single section, with again an assertion added for the resulting section to be empty.
- Extend the enumerating of .debug_* to ELF. Note that for Clang adding of .debug_macinfo is necessary. Amend this by its Dwarf5 counterpart, .debug_macro, then as well (albeit more may need adding for full coverage).
You might also want to add that LLVM ld requires explicit handling of .symtab, .strtab and .shstrtab.
Quoted 3 lines
Suggested-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>
Thanks, Roger.