[PATCH] ldlang.c: do not warn/error for linker-created empty orphan sections

Rasmus Villemoes rasmus.villemoes@prevas.dk
Mon Dec 17 22:42:00 GMT 2018

Using a custom linker script (based on one from the old toolchain) for
building a VxWorks kernel, I get "warning: orphan section ..." for some
linker-generated sections (.glink, .iplt, .rela.iplt, .branch_lt). Since
they end up without contents anyway, and are thus discarded, it seems
sensible to ignore such sections for the purpose of

I could work around it in the linker script by naming these input
sections (copying stanzas from the standard linker scripts), but then
I'd also have to put in some ASSERT machinery to check that they are
indeed empty - the point of using a custom linker script and
orphan-handling=error is to know exactly which sections are in the input
and output, and investigate if the compiler or linker ends up
introducing something unexpected.

I also considered introducing two new orphan-handling
modes (error-relaxed, warn-relaxed), but this mostly a POC/RFC, so I'll
leave such a mostly mechanical change for a potental v2.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
 ld/ldlang.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 9826479b56..3c7fac7856 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -6710,7 +6710,8 @@ ldlang_place_orphan (asection *s)
       const char *name = s->name;
       int constraint = 0;
-      if (config.orphan_handling == orphan_handling_error)
+      if (config.orphan_handling == orphan_handling_error &&
+	  !((s->flags & SEC_LINKER_CREATED) && s->size == 0))
 	einfo (_("%X%P: error: unplaced orphan section `%pA' from `%pB'\n"),
 	       s, s->owner);
@@ -6728,7 +6729,8 @@ ldlang_place_orphan (asection *s)
 	  lang_add_section (&os->children, s, NULL, os);
-      if (config.orphan_handling == orphan_handling_warn)
+      if (config.orphan_handling == orphan_handling_warn &&
+	  !((s->flags & SEC_LINKER_CREATED) && s->size == 0))
 	einfo (_("%P: warning: orphan section `%pA' from `%pB' being "
 		 "placed in section `%s'\n"),
 	       s, s->owner, os->name);

More information about the Binutils mailing list