bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/25207] New: ld: support --image-base= for elf (and -Ttext-segmen


From: i at maskray dot me
Subject: [Bug ld/25207] New: ld: support --image-base= for elf (and -Ttext-segment -z separate-code strangeness)
Date: Tue, 19 Nov 2019 23:26:29 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=25207

            Bug ID: 25207
           Summary: ld: support --image-base= for elf (and -Ttext-segment
                    -z separate-code strangeness)
           Product: binutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: i at maskray dot me
  Target Milestone: ---

% cat a.c
int main() {}

% gcc -fuse-ld=bfd a.c -Wl,-Ttext-segment,0x300000 -z noseparate-code -o a;
readelf -Wl a
...
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  PHDR           0x000040 0x0000000000300040 0x0000000000300040 0x0001f8
0x0001f8 R   0x8
  INTERP         0x000238 0x0000000000300238 0x0000000000300238 0x00001c
0x00001c R   0x1
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
  LOAD           0x000000 0x0000000000300000 0x0000000000300000 0x0007a8
0x0007a8 R E 0x1000
  LOAD           0x000e18 0x0000000000301e18 0x0000000000301e18 0x000210
0x000218 RW  0x1000
...

When -z separate-code is specified, there will be two R PT_LOAD. Notably,
-Ttext-segment specifies the address of the first R, instead of the text
segment (RX).
Or we may argue that the traditional "text segment" includes both the first R
and the RX...

% gcc -fuse-ld=bfd a.c -Wl,-Ttext-segment,0x300000 -z separate-code -o a;
readelf -Wl a
...
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  PHDR           0x000040 0x0000000000300040 0x0000000000300040 0x000268
0x000268 R   0x8
  INTERP         0x0002a8 0x00000000003002a8 0x00000000003002a8 0x00001c
0x00001c R   0x1
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
  LOAD           0x000000 0x0000000000300000 0x0000000000300000 0x000530
0x000530 R   0x1000
  LOAD           0x001000 0x0000000000301000 0x0000000000301000 0x00019d
0x00019d R E 0x1000
  LOAD           0x002000 0x0000000000302000 0x0000000000302000 0x000148
0x000148 R   0x1000
  LOAD           0x002e18 0x0000000000303e18 0x0000000000303e18 0x000210
0x000218 RW  0x1000
...

As a better name for specifying the base address, we can introduce a new elf
option --image-base=0x300000 (it exists in pe). The LLVM linker lld has
supported --image-base since 2016-07-12 (https://reviews.llvm.org/D22116).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]