[llvm-bugs] [Bug 38747] New: lld -r omits .note.GNU-stack (implying executable stack to bfd/gold)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 28 16:04:30 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38747

            Bug ID: 38747
           Summary: lld -r omits .note.GNU-stack (implying executable
                    stack to bfd/gold)
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: rprichard at google.com
                CC: llvm-bugs at lists.llvm.org

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
https://github.com/android-ndk/ndk/issues/779.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180828/706d4ce4/attachment.html>


More information about the llvm-bugs mailing list