[llvm-bugs] [Bug 49846] LLD executable segfaults with ld.bfd linker script

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 15 22:54:02 PDT 2021


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

Fangrui Song <i at maskray.me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED
                 CC|                            |i at maskray.me

--- Comment #1 from Fangrui Song <i at maskray.me> ---
With traditional -z noseparate-code, GNU ld defaults to a RX/R/RW program
header layout. With -z separate-code (default on Linux/x86 from binutils 2.31
onwards), GNU ld defaults to a R/RX/R/RW program header layout.

I think your script is a -z noseparate-code layout.

LLD defaults to R/RX/RW(RELRO)/RW(non-RELRO). With --rosegment, LLD uses
RX/RW(RELRO)/RW(non-RELRO).

GNU ld's -z noseparate-code layout is not compatible with LLD --rosegment
because there is no maxpagesize alignment between text and rodata like:

  . = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. &
(CONSTANT (MAXPAGESIZE) - 1)));

So the two PT_LOAD (RX) PT_LOAD (R) will actually overlap at runtime and the
executable segment will be remapped as readonly and the program will crash.

If you feed a ld.bfd -z separate-code linker script into ld.lld --rosegment, it
should work.

-- 
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/20210416/6336a624/attachment.html>


More information about the llvm-bugs mailing list