[llvm-bugs] [Bug 46112] New: RISC-V binary does not respect page alignment

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 27 18:24:37 PDT 2020


            Bug ID: 46112
           Summary: RISC-V binary does not respect page alignment
           Product: lld
           Version: unspecified
          Hardware: Other
                OS: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: xxuejie at gmail.com
                CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com

A sample code to reproduce this bug can be found at here:
https://gist.github.com/xxuejie/2825d4d0526c09f742d1ec4491deeaff, it just
contains some sillylogic so as to make sure the binary contains an executable
section, a writable section and a readable section.

First, let's compile the code:

clang --target=riscv64 -mno-relax -c -o test.o test.c

Then let's try link the code(I'm testing this on Linux but I would assume the
same bug applies elsewhere):

ld.lld test.o -o test

If we check the ELF generated here, it contains the following sections:

  LOAD           0x0000000000000000 0x0000000000010000 0x0000000000010000
                 0x00000000000001d8 0x00000000000001d8  R      0x1000
  LOAD           0x00000000000001d8 0x00000000000111d8 0x00000000000111d8
                 0x000000000000011e 0x000000000000011e  R E    0x1000
  LOAD           0x00000000000002f8 0x00000000000122f8 0x00000000000122f8
                 0x0000000000000000 0x0000000000000004  RW     0x1000

We can see that latter sections start at some offset in the designated pages,
not the beginning of the page. This result won't change if we use --no-nmagic
which I suppose should fix the problem. I tried both LLVM 10 and the latest git
HEAD, they both have this behavior.

So am I understanding page alignment rule wrong here? Or is there anyway we can
make sure in each section, the generated code starts from the beginning of the

Many thanks for the help

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/20200528/6c587f49/attachment.html>

More information about the llvm-bugs mailing list