Skip to content

Commit

Permalink
Discard .comment and .note sections when linking
Browse files Browse the repository at this point in the history
When not mentioned in the linker script, these sections can be inserted
by default and may be placed before _start, with ".note.gnu.build-id" in
particular being problematic.  Since these sections are metadata inserted
by the compiler/linker toolchain and have no standard meaning, there is
currently no compelling reason to keep them around.

This commit changes this on all platforms, since ELF is architecture
independent and this problem probably can show up on any architecture.

Suggested-by: John Sullivan <[email protected]>
  • Loading branch information
ebiggers committed Apr 8, 2014
1 parent eeb8f48 commit 8e743cd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compile/arch/mips/ld.script
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ SECTIONS {
*(COMMON) /* extra sections that are common */
_end = . ; /* end of image constant */
}

/* Discard comment and note (but not debugging) sections. Some
* versions of GNU ld would otherwise automatically place the
* ".note.gnu.build-id" section before _start! */
/DISCARD/ : {
*(.comment .comment.* .note .note.*)
}
}
7 changes: 7 additions & 0 deletions compile/platforms/arm-qemu/ld.script
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ SECTIONS {

. = ALIGN(64);
_end = .;

/* Discard comment and note (but not debugging) sections. Some
* versions of GNU ld would otherwise automatically place the
* ".note.gnu.build-id" section before _start! */
/DISCARD/ : {
*(.comment .comment.* .note .note.*)
}
}
7 changes: 7 additions & 0 deletions compile/platforms/arm-rpi/ld.script
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ SECTIONS {

. = ALIGN(64);
_end = .;

/* Discard comment and note (but not debugging) sections. Some
* versions of GNU ld would otherwise automatically place the
* ".note.gnu.build-id" section before _start! */
/DISCARD/ : {
*(.comment .comment.* .note .note.*)
}
}
7 changes: 7 additions & 0 deletions compile/platforms/e2100l/ld.script
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ SECTIONS {
*(COMMON) /* extra sections that are common */
_end = . ; /* end of image constant */
}

/* Discard comment and note (but not debugging) sections. Some
* versions of GNU ld would otherwise automatically place the
* ".note.gnu.build-id" section before _start! */
/DISCARD/ : {
*(.comment .comment.* .note .note.*)
}
}
7 changes: 7 additions & 0 deletions compile/platforms/x86/ld.script
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ SECTIONS {
_end = . ; /* end of image constant */
}
PROVIDE (end = .) ;

/* Discard comment and note (but not debugging) sections. Some
* versions of GNU ld would otherwise automatically place the
* ".note.gnu.build-id" section before _start! */
/DISCARD/ : {
*(.comment .comment.* .note .note.*)
}
}

0 comments on commit 8e743cd

Please sign in to comment.