bug-binutils
[Top][All Lists]
Advanced

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

[Bug gold/30552] New: gold linker produces overlapped segments when -ros


From: Vasily.Dybala at kaspersky dot com
Subject: [Bug gold/30552] New: gold linker produces overlapped segments when -rosegment is used
Date: Wed, 14 Jun 2023 09:26:16 +0000

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

            Bug ID: 30552
           Summary: gold linker produces overlapped segments when
                    -rosegment is used
           Product: binutils
           Version: 2.38
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gold
          Assignee: ccoutant at gmail dot com
          Reporter: Vasily.Dybala at kaspersky dot com
                CC: ian at airs dot com
  Target Milestone: ---

Hello, 
I try to link simple test program. As a result I get overlapped segments. And
non-working binary.

Minimal example:

> cat m.c
int main(void) { return 0; }

> gcc -c m.c
ld.gold -rosegment -Ttext 0x08500000 -no-pie m.o

> ld.gold -v
GNU gold (GNU Binutils for Ubuntu 2.38) 1.16

> readelf -lW a.out

readelf -lW a.out 

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 4 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  LOAD           0x000000 0x0000000008500000 0x0000000008500000 0x00012b
0x00012b R E 0x1000
  LOAD           0x000130 0x0000000008500130 0x0000000008500130 0x000038
0x000038 R   0x1000
  LOAD           0x001000 0x0000000008501000 0x0000000008501000 0x000000
0x000000 RW  0x1000
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000
0x000000 RW  0x10

Please look at MemSiz of first LOAD segment - it ends at address 0x850012b
and VirtAddr of second LOAD segment - it starts at address 0x8500130

Actually, segments will be rounded due to Align field to be loaded by OS.
So end address of first LOAD segment will be rounded to 0x8501000. So we have
range [0x8501000 .. 0x8501000) - 1 Page.

And start address of second LOAD segment will be rounded to 0x8500000. So we
also have range [0x8501000 .. 0x8501000) - 1 Page.

But both segments have different memory access flags, and cannot be merged.

Actually, second segment must have start address at 0x850100 instead of
0x8500130

Also I try to add flag -rosegment-gap, But seems, linker just ignore it.

Whole command line flags to produce real application:

> ld.gold --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed 
> -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -z now -z relro -o tst 
> /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o 
> /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o 
> /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/9 
> -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu 
> -L/usr/lib/gcc/x86_64-linux-gnu/9/../../../../lib -L/lib/x86_64-linux-gnu 
> -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib 
> -L/usr/lib/gcc/x86_64-linux-gnu/9/../../.. m.o -lgcc --push-state --as-needed 
> -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state 
> /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o 
> /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o -rosegment 
> -Ttext 0x08500000 -no-pie
> ./tst
Segmentation fault (core dumped)

If remove -rosegment flag from previous command - binary is successfully
launches.

System information:
> ld.gold -v
GNU gold (GNU Binutils for Ubuntu 2.38) 1.16

> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy

-- 
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]