x86/build: use --orphan-handling linker option if available
PATCH v2 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).
---
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
@@ -120,6 +120,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) \
@@ -146,7 +148,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
@@ -220,7 +222,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 +95 -67
216 lines not on this page · raw message
Quoted 19 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.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).
Quoted 2 lines
Suggested-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>
LGTM, just two questions.
Quoted 73 lines
---
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@@ -120,6 +120,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) \@@ -146,7 +148,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@@ -220,7 +222,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 +7
-0@@ -12,6 +12,13 @@ #undef __XEN_VIRT_START #define __XEN_VIRT_START __image_base__ #define DECL_SECTION(x) x : +/* + * Use the NOLOAD directive, despite currently ignored by (at least) GNU ld + * for PE output, in order to record that we'd prefer these sections to not + * be loaded into memory. + */ +#define DECL_DEBUG(x, a) #x ALIGN(a) (NOLOAD) : { *(x) } +#define DECL_DEBUG2(x, y, a) #x ALIGN(a) (NOLOAD) : { *(x) *(y) } ENTRY(efi_start)
xen/arch/x86/xen.lds.S ENTRY(efi_start) · line 30
Quoted 5 lines
xen/arch/x86/xen.lds.S +2
-0@@ -19,6 +26,8 @@ ENTRY(efi_start) #define FORMAT "elf64-x86-64" #define DECL_SECTION(x) #x : AT(ADDR(#x) - __XEN_VIRT_START) +#define DECL_DEBUG(x, a) #x 0 : { *(x) } +#define DECL_DEBUG2(x, y, a) #x 0 : { *(x) *(y) }
Would it be helpful to place those in a
xen/arch/x86/xen.lds.S SECTIONS · line 195
Quoted 12 lines
xen/arch/x86/xen.lds.S +5
-0ENTRY(start_pa)@@ -179,6 +188,13 @@ SECTIONS #endif #endif +#ifndef EFI + /* Retain these just for the purpose of possible analysis tools. */ + DECL_SECTION(.note) { + *(.note.*) + } PHDR(note) PHDR(text)
Wouldn't it be enough to place it in the note program header?
The buildid note is already placed in .rodata, so any remaining notes don't need to be in a LOAD section?
Quoted 23 lines
xen/arch/x86/xen.lds.S +16
-0+#endif + _erodata = .; . = ALIGN(SECTION_ALIGN);@@ -266,6 +282,32 @@ SECTIONS __ctors_end = .; } PHDR(text) +#ifndef EFI + /* + * With --orphan-sections=warn (or =error) we need to handle certain linker + * generated sections. These are all expected to be empty; respective + * ASSERT()s can be found towards the end of this file. + */ + DECL_SECTION(.got) { + *(.got) + } PHDR(text) + DECL_SECTION(.got.plt) { + *(.got.plt) + } PHDR(text) + DECL_SECTION(.igot.plt) { + *(.igot.plt)
xen/arch/x86/xen.lds.S SECTIONS · line 308
Quoted 10 lines
xen/arch/x86/xen.lds.S +10
-0+ } PHDR(text) + DECL_SECTION(.iplt) { + *(.iplt) + } PHDR(text) + DECL_SECTION(.plt) { + *(.plt) + } PHDR(text) + DECL_SECTION(.rela) { + *(.rela.*) + } PHDR(text)
Why do you need to explicitly place those in the text program header?
Thanks, Roger.
Quoted 20 lines · Roger Pau Monné
Quoted 19 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.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).
Quoted 4 lines
Quoted 2 lines
Suggested-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>LGTM, just two questions.
Sure, just that ...
Quoted 8 lines
xen/arch/x86/xen.lds.S ENTRY(efi_start) · line 30
Quoted 6 lines
xen/arch/x86/xen.lds.S +2
-0@@ -19,6 +26,8 @@ ENTRY(efi_start) #define FORMAT "elf64-x86-64" #define DECL_SECTION(x) #x : AT(ADDR(#x) - __XEN_VIRT_START) +#define DECL_DEBUG(x, a) #x 0 : { *(x) } +#define DECL_DEBUG2(x, y, a) #x 0 : { *(x) *(y) }Would it be helpful to place those in a
... you may have had a 3rd one?
Quoted 12 lines
xen/arch/x86/xen.lds.S SECTIONS · line 195
Quoted 9 lines
xen/arch/x86/xen.lds.S +5
-0@@ -179,6 +188,13 @@ SECTIONS #endif #endif +#ifndef EFI + /* Retain these just for the purpose of possible analysis tools. */ + DECL_SECTION(.note) { + *(.note.*) + } PHDR(note) PHDR(text)Wouldn't it be enough to place it in the note program header?
Quoted 2 lines
The buildid note is already placed in .rodata, so any remaining notes don't need to be in a LOAD section?
All the notes will be covered by the NOTE phdr. I had this much later in the script originally, but then the NOTE phdr covered large parts of .init.*. Clearly that yields invalid notes, which analysis (or simple dumping) tools wouldn't be happy about. We might be able to add 2nd NOTE phdr, but mkelf32 assumes exactly 2 phdrs if it finds more than one, so changes there would likely be needed then (which I'd like to avoid for the moment). I'm also not sure in how far tools can be expected to look for multiple NOTE phdrs ...
Quoted 27 lines
Quoted 27 lines
xen/arch/x86/xen.lds.S +20
-0+#endif + _erodata = .; . = ALIGN(SECTION_ALIGN);@@ -266,6 +282,32 @@ SECTIONS __ctors_end = .; } PHDR(text) +#ifndef EFI + /* + * With --orphan-sections=warn (or =error) we need to handle certain linker + * generated sections. These are all expected to be empty; respective + * ASSERT()s can be found towards the end of this file. + */ + DECL_SECTION(.got) { + *(.got) + } PHDR(text) + DECL_SECTION(.got.plt) { + *(.got.plt) + } PHDR(text) + DECL_SECTION(.igot.plt) { + *(.igot.plt) + } PHDR(text) + DECL_SECTION(.iplt) { + *(.iplt) + } PHDR(text)
Quoted 8 lines
xen/arch/x86/xen.lds.S SECTIONS · line 308
Quoted 6 lines
xen/arch/x86/xen.lds.S +6
-0+ DECL_SECTION(.plt) { + *(.plt) + } PHDR(text) + DECL_SECTION(.rela) { + *(.rela.*) + } PHDR(text)Why do you need to explicitly place those in the text program header?
I guess that's largely for consistency with all other directives. With the assertions that these need to be empty, we might get away without, as long as no linker would decide to set up another zero-size phdr for them.
Jan
Quoted 30 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 19 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.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).Quoted 4 lines
Quoted 2 lines
Suggested-by Roger Pau Monné <[email protected]>Signed-off-by Jan Beulich <[email protected]>LGTM, just two questions.
Sure, just that ...
Quoted 2 lines
Quoted 2 lines
(quoted diff) +0
-0@@ -19,6 +26,8 @@ ENTRY(efi_start)
Quoted 8 lines
Quoted 6 lines
xen/arch/x86/xen.lds.S ENTRY(efi_start) · line 30
Quoted 4 lines
xen/arch/x86/xen.lds.S +2
-0#define FORMAT "elf64-x86-64" #define DECL_SECTION(x) #x : AT(ADDR(#x) - __XEN_VIRT_START) +#define DECL_DEBUG(x, a) #x 0 : { *(x) } +#define DECL_DEBUG2(x, y, a) #x 0 : { *(x) *(y) }Would it be helpful to place those in a
... you may have had a 3rd one?
Oh, no, I just forgot to remove this. I was going to ask whether we could place those in something akin to a PT_NOLOAD program section, but that doesn't exist AFAICT (and even if possible would require adjustments to mkelf32).
Quoted 16 lines
Quoted 13 lines
xen/arch/x86/xen.lds.S SECTIONS · line 195
Quoted 10 lines
xen/arch/x86/xen.lds.S +5
-0@@ -179,6 +188,13 @@ SECTIONS #endif #endif +#ifndef EFI + /* Retain these just for the purpose of possible analysis tools. */ + DECL_SECTION(.note) { + *(.note.*) + } PHDR(note) PHDR(text)Wouldn't it be enough to place it in the note program header?
Quoted 2 lines
The buildid note is already placed in .rodata, so any remaining notes don't need to be in a LOAD section?
Quoted 8 lines
All the notes will be covered by the NOTE phdr. I had this much later in the script originally, but then the NOTE phdr covered large parts of .init.*. Clearly that yields invalid notes, which analysis (or simple dumping) tools wouldn't be happy about. We might be able to add 2nd NOTE phdr, but mkelf32 assumes exactly 2 phdrs if it finds more than one, so changes there would likely be needed then (which I'd like to avoid for the moment). I'm also not sure in how far tools can be expected to look for multiple NOTE phdrs ...
But if we are adding a .note section now we might as well merge it with .note.gnu.build-id:
DECL_SECTION(.note) {
__note_gnu_build_id_start = .;
*(.note.gnu.build-id)
__note_gnu_build_id_end = .;
*(.note.*)
} PHDR(note) PHDR(text)And drop the .note.Xen section?
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
xen/arch/x86/xen.lds.S +20
-0+#endif + _erodata = .; . = ALIGN(SECTION_ALIGN);@@ -266,6 +282,32 @@ SECTIONS __ctors_end = .; } PHDR(text) +#ifndef EFI + /* + * With --orphan-sections=warn (or =error) we need to handle certain linker + * generated sections. These are all expected to be empty; respective + * ASSERT()s can be found towards the end of this file. + */ + DECL_SECTION(.got) { + *(.got) + } PHDR(text) + DECL_SECTION(.got.plt) { + *(.got.plt) + } PHDR(text) + DECL_SECTION(.igot.plt) { + *(.igot.plt) + } PHDR(text) + DECL_SECTION(.iplt) { + *(.iplt) + } PHDR(text)Quoted 8 lines
xen/arch/x86/xen.lds.S SECTIONS · line 308
Quoted 6 lines
xen/arch/x86/xen.lds.S +6
-0+ DECL_SECTION(.plt) { + *(.plt) + } PHDR(text) + DECL_SECTION(.rela) { + *(.rela.*) + } PHDR(text)Why do you need to explicitly place those in the text program header?
Quoted 3 lines
I guess that's largely for consistency with all other directives. With the assertions that these need to be empty, we might get away without, as long as no linker would decide to set up another zero-size phdr for them.
We already set the debug sections to not be part of any program header and seem to get away with it. I'm not sure how different the sections handled below would be, linkers might indeed want to place them regardless?
If so it might be good to add a comment that while those should be empty (and thus don't end up in any program header) we assign them to the text one in order to avoid the linker from creating a new program header for them.
Thanks, Roger.
Quoted 30 lines · Roger Pau Monné
Quoted 17 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
xen/arch/x86/xen.lds.S SECTIONS · line 195
Quoted 9 lines · Jan Beulich
xen/arch/x86/xen.lds.S +5
-0@@ -179,6 +188,13 @@ SECTIONS #endif #endif +#ifndef EFI + /* Retain these just for the purpose of possible analysis tools. */ + DECL_SECTION(.note) { + *(.note.*) + } PHDR(note) PHDR(text)Wouldn't it be enough to place it in the note program header?
Quoted 2 lines
The buildid note is already placed in .rodata, so any remaining notes don't need to be in a LOAD section?
Quoted 8 lines
All the notes will be covered by the NOTE phdr. I had this much later in the script originally, but then the NOTE phdr covered large parts of .init.*. Clearly that yields invalid notes, which analysis (or simple dumping) tools wouldn't be happy about. We might be able to add 2nd NOTE phdr, but mkelf32 assumes exactly 2 phdrs if it finds more than one, so changes there would likely be needed then (which I'd like to avoid for the moment). I'm also not sure in how far tools can be expected to look for multiple NOTE phdrs ...
But if we are adding a .note section now we might as well merge it with .note.gnu.build-id:
Quoted 8 lines
DECL_SECTION(.note) { __note_gnu_build_id_start = .; *(.note.gnu.build-id) __note_gnu_build_id_end = .; *(.note.*) } PHDR(note) PHDR(text)And drop the .note.Xen section?
In an ideal world we likely could, yes. But do we know for sure that nothing recognizes the Xen notes by section name? .note.gnu.build-id cannot be folded in any event - see the rule for generating note.o, to be used by xen.efi linking in certain cases.
Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
Quoted 23 lines
xen/arch/x86/xen.lds.S +16
-0+#endif + _erodata = .; . = ALIGN(SECTION_ALIGN);@@ -266,6 +282,32 @@ SECTIONS __ctors_end = .; } PHDR(text) +#ifndef EFI + /* + * With --orphan-sections=warn (or =error) we need to handle certain linker + * generated sections. These are all expected to be empty; respective + * ASSERT()s can be found towards the end of this file. + */ + DECL_SECTION(.got) { + *(.got) + } PHDR(text) + DECL_SECTION(.got.plt) { + *(.got.plt) + } PHDR(text) + DECL_SECTION(.igot.plt) { + *(.igot.plt)xen/arch/x86/xen.lds.S SECTIONS · line 308
Quoted 10 lines
xen/arch/x86/xen.lds.S +10
-0+ } PHDR(text) + DECL_SECTION(.iplt) { + *(.iplt) + } PHDR(text) + DECL_SECTION(.plt) { + *(.plt) + } PHDR(text) + DECL_SECTION(.rela) { + *(.rela.*) + } PHDR(text)Why do you need to explicitly place those in the text program header?
Quoted 8 lines
Quoted 3 lines
I guess that's largely for consistency with all other directives. With the assertions that these need to be empty, we might get away without, as long as no linker would decide to set up another zero-size phdr for them.
We already set the debug sections to not be part of any program header and seem to get away with it. I'm not sure how different the sections handled below would be, linkers might indeed want to place them regardless?
Simply because I don't know I'd like to be on the safe side. Debug sections can't really be taken as reference: At least GNU ld heavily special-cases them anyway.
Quoted 4 lines
If so it might be good to add a comment that while those should be empty (and thus don't end up in any program header) we assign them to the text one in order to avoid the linker from creating a new program header for them.
I'll add a sentence to the comment I'm already adding here.
Jan
Quoted 38 lines · Jan Beulich
Quoted 37 lines · Roger Pau Monné
Quoted 17 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
xen/arch/x86/xen.lds.S SECTIONS · line 195
Quoted 9 lines · Jan Beulich
xen/arch/x86/xen.lds.S +5
-0@@ -179,6 +188,13 @@ SECTIONS #endif #endif +#ifndef EFI + /* Retain these just for the purpose of possible analysis tools. */ + DECL_SECTION(.note) { + *(.note.*) + } PHDR(note) PHDR(text)Wouldn't it be enough to place it in the note program header?
Quoted 2 lines
The buildid note is already placed in .rodata, so any remaining notes don't need to be in a LOAD section?
Quoted 8 lines
All the notes will be covered by the NOTE phdr. I had this much later in the script originally, but then the NOTE phdr covered large parts of .init.*. Clearly that yields invalid notes, which analysis (or simple dumping) tools wouldn't be happy about. We might be able to add 2nd NOTE phdr, but mkelf32 assumes exactly 2 phdrs if it finds more than one, so changes there would likely be needed then (which I'd like to avoid for the moment). I'm also not sure in how far tools can be expected to look for multiple NOTE phdrs ...
But if we are adding a .note section now we might as well merge it with .note.gnu.build-id:
DECL_SECTION(.note) { __note_gnu_build_id_start = .; *(.note.gnu.build-id) __note_gnu_build_id_end = .; *(.note.*) } PHDR(note) PHDR(text)
Quoted 4 lines
Quoted 1 line
And drop the .note.Xen section?
In an ideal world we likely could, yes. But do we know for sure that nothing recognizes the Xen notes by section name?
Wouldn't that be wrong? In the elfnotes.h file it's clearly specified that Xen notes live in a PT_NOTE program header and have 'Xen' in the name field. There's no requirement of them being in any specific section.
Quoted 3 lines
.note.gnu.build-id
cannot be folded in any event - see the rule for generating note.o, to be used by xen.efi linking in certain cases.
Right, so we need to keep the .note.gnu.build-id section, but we could likely fold .note.Xen into .note I think?
Or at least add a comment to mention that we don't want to fold .note.Xen into .note in case there are tools that search for specific Xen notes to be contained in .note.Xen.
Quoted 49 lines
Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
Quoted 23 lines
xen/arch/x86/xen.lds.S +16
-0+#endif + _erodata = .; . = ALIGN(SECTION_ALIGN);@@ -266,6 +282,32 @@ SECTIONS __ctors_end = .; } PHDR(text) +#ifndef EFI + /* + * With --orphan-sections=warn (or =error) we need to handle certain linker + * generated sections. These are all expected to be empty; respective + * ASSERT()s can be found towards the end of this file. + */ + DECL_SECTION(.got) { + *(.got) + } PHDR(text) + DECL_SECTION(.got.plt) { + *(.got.plt) + } PHDR(text) + DECL_SECTION(.igot.plt) { + *(.igot.plt)xen/arch/x86/xen.lds.S SECTIONS · line 308
Quoted 10 lines
xen/arch/x86/xen.lds.S +10
-0+ } PHDR(text) + DECL_SECTION(.iplt) { + *(.iplt) + } PHDR(text) + DECL_SECTION(.plt) { + *(.plt) + } PHDR(text) + DECL_SECTION(.rela) { + *(.rela.*) + } PHDR(text)Why do you need to explicitly place those in the text program header?
Quoted 8 lines
Quoted 3 lines
I guess that's largely for consistency with all other directives. With the assertions that these need to be empty, we might get away without, as long as no linker would decide to set up another zero-size phdr for them.
We already set the debug sections to not be part of any program header and seem to get away with it. I'm not sure how different the sections handled below would be, linkers might indeed want to place them regardless?
Simply because I don't know I'd like to be on the safe side. Debug sections can't really be taken as reference: At least GNU ld heavily special-cases them anyway.
Quoted 6 lines
Quoted 4 lines
If so it might be good to add a comment that while those should be empty (and thus don't end up in any program header) we assign them to the text one in order to avoid the linker from creating a new program header for them.
I'll add a sentence to the comment I'm already adding here.
Thanks, Roger.
Quoted 41 lines · Roger Pau Monné
Quoted 40 lines · Jan Beulich
Quoted 38 lines · Roger Pau Monné
Quoted 17 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
xen/arch/x86/xen.lds.S SECTIONS · line 195
Quoted 9 lines · Jan Beulich
xen/arch/x86/xen.lds.S +5
-0@@ -179,6 +188,13 @@ SECTIONS #endif #endif +#ifndef EFI + /* Retain these just for the purpose of possible analysis tools. */ + DECL_SECTION(.note) { + *(.note.*) + } PHDR(note) PHDR(text)Wouldn't it be enough to place it in the note program header?
Quoted 2 lines
The buildid note is already placed in .rodata, so any remaining notes don't need to be in a LOAD section?
Quoted 8 lines
All the notes will be covered by the NOTE phdr. I had this much later in the script originally, but then the NOTE phdr covered large parts of .init.*. Clearly that yields invalid notes, which analysis (or simple dumping) tools wouldn't be happy about. We might be able to add 2nd NOTE phdr, but mkelf32 assumes exactly 2 phdrs if it finds more than one, so changes there would likely be needed then (which I'd like to avoid for the moment). I'm also not sure in how far tools can be expected to look for multiple NOTE phdrs ...
But if we are adding a .note section now we might as well merge it with .note.gnu.build-id:
DECL_SECTION(.note) { __note_gnu_build_id_start = .; *(.note.gnu.build-id) __note_gnu_build_id_end = .; *(.note.*) } PHDR(note) PHDR(text)And drop the .note.Xen section?
Quoted 7 lines
Quoted 2 lines
In an ideal world we likely could, yes. But do we know for sure that nothing recognizes the Xen notes by section name?
Wouldn't that be wrong? In the
elfnotes.hfile it's clearly specified that Xen notes live in aPT_NOTEprogram header and have 'Xen' in the name field. There's no requirement of them being in any specific section.
True. But ELF also tells us to not go from section names (only), but to consider type and attribute as well. Yet what do most tools do?
Quoted 10 lines
Quoted 3 lines
.note.gnu.build-id
cannot be folded in any event - see the rule for generating note.o, to be used by xen.efi linking in certain cases.Right, so we need to keep the .note.gnu.build-id section, but we could likely fold .note.Xen into .note I think?
Or at least add a comment to mention that we don't want to fold .note.Xen into .note in case there are tools that search for specific Xen notes to be contained in .note.Xen.
I can add such a comment, sure.
Jan