[llvm-bugs] [Bug 43997] [LLD/ELF] LLD change inflates elf binary size when linked with no-rosegment

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 15 14:10:15 PST 2019


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

Fangrui Song <i at maskray.me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Fangrui Song <i at maskray.me> ---
If I remove --no-rosegment, the file will be 4.9M

  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  PHDR           0x000040 0x0000000000200040 0x0000000000200040 0x0002a0
0x0002a0 R   0x8
  LOAD           0x000000 0x0000000000200000 0x0000000000200000 0x0002e0
0x0002e0 R   0x1000
  LOAD           0x001000 0x0000000060000000 0x0000000060000000 0x245dc6
0x245dc6 R E 0x1000
  LOAD           0x246dc8 0x0000000060246dc8 0x0000000060246dc8 0x177964
0x177964 R   0x1000<Paste>

  [Nr] Name              Type            Address          Off    Size   ES Flg
Lk Inf Al
  [ 1] .text             PROGBITS        0000000060000000 001000 245dc6 00  AX 
0   0 32

If I keep it, the file will be 1.6G

  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  PHDR           0x000040 0x0000000000200040 0x0000000000200040 0x0001f8
0x0001f8 R   0x8
  LOAD           0x000000 0x0000000000200000 0x0000000000200000 0x601bed00
0x601bed00 R E 0x1000
  LOAD           0x601bed00 0x00000000603bfd00 0x00000000603bfd00 0x0008e0
0x0008e0 RW  0x1000

  [Nr] Name              Type            Address          Off    Size   ES Flg
Lk Inf Al
  [ 1] .text             PROGBITS        0000000060000000 5fe00000 245dc6 00 
AX  0   0 32

The large file size is due to the large sh_offset of .text, which is to meet
the requirement of `--Ttext 0x60000000`.

A lot of -Ttext assumes the traditional GNU ld layout where there is a RX
segment but no R segment.

Before "[ELF] Map the ELF header at imageBase", we had a weird layout where the
ELF header and PT_PHDR is mapped high addresses. So the commit actually fixed a
problem.

  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  PHDR           0x000040 0x000000005ffff040 0x000000005ffff040 0x0001f8
0x0001f8 R   0x8
  LOAD           0x000000 0x000000005ffff000 0x000000005ffff000 0x3bfd00
0x3bfd00 R E 0x1000
  LOAD           0x3bfd00 0x00000000603bfd00 0x00000000603bfd00 0x0008e0
0x0008e0 RW  0x1000

To get that behavior, you may need to add --image-base=0x5ffff000 beside -Ttext
0x60000000.

I have looked at my /usr/bin/qemu-x86_64-static, which maps the ELF header at
0x60000000, instead of 0x5ffff000.
So I believe the better fix is to remove -Ttext and add
--image-base=0x60000000.

-- 
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/20191115/6637be8a/attachment-0001.html>


More information about the llvm-bugs mailing list