<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - lld -r omits .note.GNU-stack (implying executable stack to bfd/gold)"
href="https://bugs.llvm.org/show_bug.cgi?id=38747">38747</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>lld -r omits .note.GNU-stack (implying executable stack to bfd/gold)
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>ELF
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rprichard@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>If I use lld's -r to combine two object files into one, the output lacks a
.note.GNU-stack section. The lack of the section implies to bfd and gold that
the file needs an executable stack. lld itself ignores the sections:
// The GNU linker uses .note.GNU-stack section as a marker indicating
// that the code in the object file does not expect that the stack is
// executable (in terms of NX bit). If all input files have the marker,
// the GNU linker adds a PT_GNU_STACK segment to tells the loader to
// make the stack non-executable. Most object files have this section as
// of 2017.
//
// But making the stack non-executable is a norm today for security
// reasons. Failure to do so may result in a serious security issue.
// Therefore, we make LLD always add PT_GNU_STACK unless it is
// explicitly told to do otherwise (by -z execstack). Because the stack
// executable-ness is controlled solely by command line options,
// .note.GNU-stack sections are simply ignored.
if (Name == ".note.GNU-stack")
return &InputSection::Discarded;
Example:
test1.c
void func1() {}
test2.c
void func2() {}
test3.c
int main() { return 0; }
Expected Output (gold+gold):
$ /x/clang6/bin/clang test1.c test2.c -nostdlib -Wl,-r -o test12.o
-fuse-ld=gold
$ readelf -SW test12.o | grep -i stack
[ 5] .note.GNU-stack PROGBITS 0000000000000000 000128 000000 00
0 0 0
$ /x/clang6/bin/clang test12.o test3.c -fuse-ld=gold
$ readelf -lW a.out | grep STACK
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000
0x000000 RW 0x10
Actual Output (lld+gold):
$ /x/clang6/bin/clang test1.c test2.c -nostdlib -Wl,-r -o test12.o
-fuse-ld=lld
$ readelf -SW test12.o | grep -i stack
<nothing>
$ /x/clang6/bin/clang test12.o test3.c -fuse-ld=gold
$ readelf -lW a.out | grep STACK
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000
0x000000 RWE 0x10
Output with --warn-execstack
$ /x/clang6/bin/clang test12.o test3.c -fuse-ld=gold -Wl,--warn-execstack
/usr/bin/ld.gold: warning: test12.o: missing .note.GNU-stack section
implies executable stack
lld has a --warn-execstack option, but it's only there for compatibility and
doesn't do anything (for now?).
Should lld emit a .note.GNU-stack marker section for -r output? If it did, I'd
assume it could set the executable bit according to the -z [no]execstack flag.
I noticed this issue while working on
<a href="https://github.com/android-ndk/ndk/issues/779">https://github.com/android-ndk/ndk/issues/779</a>.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>