Repository navigation
feat: implement --orphan-handling - #2566
Conversation
8ad864c to
3368559
Compare
There was a problem hiding this comment.
Here's a few tests that fail. If any are too hard to fix now and/or you don't think they're important, just say.
index 80c1cbb6b3..2bfe2199b8 100644
--- a/wild/tests/sources/elf/linker-script-orphan-handling/linker-script-orphan-handling.c
+++ b/wild/tests/sources/elf/linker-script-orphan-handling/linker-script-orphan-handling.c
@@ -1,5 +1,4 @@
-//#AbstractConfig:default
-//#LinkerScript:linker-script-orphan-handling.ld
+//#AbstractConfig:common
//#Object:runtime.c
// RISC-V: BFD complains about missing __global_pointer$ (defined in the default linker script)
//#SkipArch:riscv64
@@ -8,6 +7,9 @@
//#DiffIgnore:segment.LOAD.RW.alignment
//#DiffIgnore:segment.LOAD.RWX.alignment
+//#AbstractConfig:default:common
+//#LinkerScript:linker-script-orphan-handling.ld
+
//#Config:orphan-place:default
//#LinkArgs:--orphan-handling=place
//#Contains:.orphan_section
@@ -24,8 +26,55 @@
//#LinkArgs:--orphan-handling=discard
//#DoesNotContain:.orphan_section
+//#Config:orphan-debug-place:default
+//#CompArgs:-g
+//#LinkArgs:--orphan-handling=place
+//#ExpectSection:.debug_info
+
+//#Config:orphan-debug-discard:default
+//#CompArgs:-g
+//#LinkArgs:--orphan-handling=discard
+//#NoSection:.debug_info
+
+//#AbstractConfig:eh-frame:default
+//#CompArgs:-fasynchronous-unwind-tables -DNO_ORPHAN_VAR
+
+//#Config:orphan-eh-frame-place:eh-frame
+//#LinkArgs:--no-gc-sections --orphan-handling=place
+//#ExpectSection:.eh_frame
+
+//#Config:orphan-eh-frame-warn:eh-frame
+//#LinkArgs:--no-gc-sections --orphan-handling=warn
+//#ExpectWarning:orphan section .\.eh_frame'
+
+//#Config:orphan-eh-frame-error:eh-frame
+//#LinkArgs:--no-gc-sections --orphan-handling=error
+//#ExpectError:unplaced orphan section .\.eh_frame'
+
+//#Config:orphan-eh-frame-discard:eh-frame
+//#LinkArgs:--no-gc-sections --orphan-handling=discard
+//#NoSection:.eh_frame
+
+//#AbstractConfig:partial:common
+//#RunEnabled:false
+//#DiffEnabled:false
+
+//#Config:orphan-partial-place:partial
+//#LinkArgs:-r --orphan-handling=place
+//#ExpectSection:.orphan_section
+
+//#Config:orphan-partial-warn:partial
+//#LinkArgs:-r --orphan-handling=warn
+//#ExpectWarning:orphan section .\.orphan_section'
+
+//#Config:orphan-partial-error:partial
+//#LinkArgs:-r --orphan-handling=error
+//#ExpectError:unplaced orphan section .\.orphan_section'
+
#include "../common/runtime.h"
+#ifndef NO_ORPHAN_VAR
__attribute__((section(".orphan_section"), retain, used)) int orphan_var = 42;
+#endif
void _start(void) { exit_syscall(42); }3368559 to
3f2c55b
Compare
|
@davidlattimore should we print multiple errors for each missing section when |
There was a problem hiding this comment.
Reporting multiple errors is definitely something I think we want to address. It's possible that it might be better done in a separate PR either before or after this one, but I don't feel strongly, so if you want to keep it in this PR or partially handle it in this PR, that's also fine.
Here's a few new tests that fail. Possibly the no-script variants shouldn't be in a test with "linker-script" in its name, so if you keep these, then maybe the whole test should be renamed to just "orphan-handling".
diff --git a/wild/tests/sources/elf/linker-script-orphan-handling/linker-script-orphan-handling.c b/wild/tests/sources/elf/linker-script-orphan-handling/linker-script-orphan-handling.c
index f0009673d3..3cc7b464cd 100644
--- a/wild/tests/sources/elf/linker-script-orphan-handling/linker-script-orphan-handling.c
+++ b/wild/tests/sources/elf/linker-script-orphan-handling/linker-script-orphan-handling.c
@@ -61,6 +61,26 @@
//#LinkArgs:--no-gc-sections --orphan-handling=discard
//#ExpectSection:.eh_frame
+//#AbstractConfig:filtered-eh-frame:common
+//#LinkerScript:orphan-handling-filtered-ehframe.ld
+//#CompArgs:-fasynchronous-unwind-tables -DNO_ORPHAN_VAR
+
+//#Config:filtered-eh-frame-place:filtered-eh-frame
+//#LinkArgs:--no-gc-sections --orphan-handling=place
+//#ExpectSection:.eh_frame
+
+//#Config:filtered-eh-frame-warn:filtered-eh-frame
+//#LinkArgs:--no-gc-sections --orphan-handling=warn
+//#ExpectWarning:orphan section .\.eh_frame'
+
+//#Config:filtered-eh-frame-error:filtered-eh-frame
+//#LinkArgs:--no-gc-sections --orphan-handling=error
+//#ExpectError:unplaced orphan section .\.eh_frame'
+
+//#Config:filtered-eh-frame-discard:filtered-eh-frame
+//#LinkArgs:--no-gc-sections --orphan-handling=discard
+//#NoSection:.eh_frame
+
//#AbstractConfig:partial:common
//#RunEnabled:false
//#DiffEnabled:false
@@ -77,6 +97,26 @@
//#LinkArgs:-r --orphan-handling=error
//#ExpectError:unplaced orphan section .\.orphan_section'
+//#Config:orphan-partial-discard:partial
+//#LinkArgs:-r --orphan-handling=discard
+//#NoSection:.orphan_section
+
+//#Config:no-script-place:common
+//#LinkArgs:--orphan-handling=place
+//#ExpectSection:.orphan_section
+
+//#Config:no-script-warn:common
+//#LinkArgs:--orphan-handling=warn
+//#ExpectWarning:orphan section .\.orphan_section'
+
+//#Config:no-script-error:common
+//#LinkArgs:--orphan-handling=error
+//#ExpectError:unplaced orphan section .\.orphan_section'
+
+//#Config:no-script-discard:common
+//#LinkArgs:--orphan-handling=discard
+//#NoSection:.orphan_section
+
#include "../common/runtime.h"
#ifndef NO_ORPHAN_VAR
diff --git a/wild/tests/sources/elf/linker-script-orphan-handling/orphan-handling-filtered-ehframe.ld b/wild/tests/sources/elf/linker-script-orphan-handling/orphan-handling-filtered-ehframe.ld
new file mode 100644
index 0000000000..3d83f2b950
--- /dev/null
+++ b/wild/tests/sources/elf/linker-script-orphan-handling/orphan-handling-filtered-ehframe.ld
@@ -0,0 +1,18 @@
+ENTRY(_start)
+
+SECTIONS {
+ . = 0x600000;
+ .eh_frame : {
+ *not-an-input*.o(.eh_frame)
+ }
+ .text : {
+ *(.text*)
+ }
+ . = 0x800000;
+ .data : {
+ *(.data*)
+ }
+ .bss : {
+ *(.bss*)
+ }
+}3f2c55b to
19782ae
Compare
There was a problem hiding this comment.
It looks like there's no test for --orphan-handling=error when all sections are mapped. That case fails because of the null section when it shouldn't. Here's a test that shows it:
diff --git a/wild/tests/sources/elf/orphan-handling/orphan-handling.c b/wild/tests/sources/elf/orphan-handling/orphan-handling.c
index bc2974ef1e..22ee04eaf4 100644
--- a/wild/tests/sources/elf/orphan-handling/orphan-handling.c
+++ b/wild/tests/sources/elf/orphan-handling/orphan-handling.c
@@ -113,6 +113,10 @@
//#LinkArgs:--orphan-handling=error
//#ExpectError:unplaced orphan section .\.orphan_section'
+//#Config:no-orphans-error:common
+//#CompArgs:-DNO_ORPHAN_VAR
+//#LinkArgs:--orphan-handling=error
+
//#Config:no-script-discard:common
//#LinkArgs:--orphan-handling=discard
//#NoSection:.orphan_section| && check_orphan_placement::<P>( | ||
| args, | ||
| &obj.common.input, | ||
| &String::from_utf8_lossy(section_name), |
There was a problem hiding this comment.
I'm seeing a 20% increase in wall time for the "Resolve sections" phase. I suspect it's because we're doing UTF-8 validation for all sections.
| .lookup::<P>(section_name, file_name, input_section) | ||
| }; | ||
|
|
||
| if layout_rules.is_orphan::<P>(section_name, file_name, input_section) |
There was a problem hiding this comment.
It looks like the slowdown in section resolution is still happening. I guess it wasn't utf-8 validation, but rather this call to is_orphan. If I add args.orphan_handling() != OrphanHandling::Place && to the start of this if-statement, the section resolution slowdown seems to go away.
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
a08b55f to
2d9b9b6
Compare
--orphan-handling is used to handle sections not explicitly defined by linker scripts. It accepts four options,
placeis the default, it inserts a section not defined by a linker script implicitly.warnjust emits a warning and continues.errorwill emit an error and exit early.discardwill skip the section.