Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHDR & section mismatch in lld-linked static hello world on FreeBSD results in segfault #27086

Closed
emaste opened this issue Feb 23, 2016 · 1 comment
Labels
bugzilla Issues migrated from bugzilla lld

Comments

@emaste
Copy link
Member

emaste commented Feb 23, 2016

Bugzilla Link 26712
Resolution FIXED
Resolved on Feb 23, 2016 12:40
Version unspecified
OS FreeBSD
Blocks #23588

Extended Description

At r261576 an lld-linked hello world segfaults at program termination:

% clang -fuse-ld=lld -static hello.c
% ./a.out
Hello, world.
zsh: segmentation fault (core dumped) ./a.out

The the .dtors section in my hello world:
% readelf -S a.out | grep -A1 dtors
[15] .dtors PROGBITS 0000000000074028 00064030
0000000000000018 0000000000000000 WA 0 0 8
% readelf -x .dtors a.out

Hex dump of section '.dtors':
0x00074028 ffffffff ffffffff e0be0600 00000000 ................
0x00074038 00000000 00000000 ........

But when running:

(lldb) memory read --size 8 --format hex 0x74028
0x00074028: 0x0000000000000000 0xffffffffffffffff
0x00074038: 0x000000000006bee0 0x0000000000000000
0x00074048: 0x0000000000000000 0x0000000000000000
0x00074058: 0x0000000000000000 0x0000000000000000

The program & section headers disagree

Nearby section headers:
[10] .init PROGBITS 0000000000073de8 00063de8
0000000000000013 0000000000000000 AX 0 0 4
[11] .fini PROGBITS 0000000000073dfc 00063dfc
000000000000000e 0000000000000000 AX 0 0 4
[12] .tdata PROGBITS 0000000000074000 00064000
0000000000000004 0000000000000000 WAT 0 0 4
[13] .tbss NOBITS 0000000000074010 00064010
0000000000000068 0000000000000000 WAT 0 0 16
[14] .ctors PROGBITS 0000000000074008 00064010
0000000000000020 0000000000000000 WA 0 0 8
[15] .dtors PROGBITS 0000000000074028 00064030
0000000000000018 0000000000000000 WA 0 0 8
[16] .jcr PROGBITS 0000000000074040 00064048
0000000000000008 0000000000000000 WA 0 0 8
[17] .data PROGBITS 0000000000075000 00065000
0000000000003460 0000000000000000 WA 0 0 16
[18] .bss NOBITS 0000000000078460 00068460
000000000001d77d 0000000000000000 WA 0 0 16

% readelf -l a.out.lld

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

Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000010040 0x0000000000010040
0x0000000000000188 0x0000000000000188 R 8
LOAD 0x0000000000000000 0x0000000000010000 0x0000000000010000
0x00000000000128a0 0x00000000000128a0 R 1000
LOAD 0x0000000000013000 0x0000000000023000 0x0000000000023000
0x0000000000050e0a 0x0000000000050e0a R E 1000
LOAD 0x0000000000064000 0x0000000000074000 0x0000000000074000
0x0000000000004460 0x0000000000021bdd RW 1000
TLS 0x0000000000064000 0x0000000000074000 0x0000000000074000
0x0000000000000010 0x0000000000000080 R 10
GNU_RELRO 0x0000000000064000 0x0000000000074000 0x0000000000074000
0x0000000000000050 0x0000000000000048 R 1
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0

Section to Segment mapping:
Segment Sections...
00
01 .note.tag .rodata .eh_frame .rodata .rodata .rodata .rodata .rodata
02 .text .init .fini
03 .tdata .ctors .dtors .jcr .data .bss
04 .tdata .tbss
05 .ctors .dtors .jcr
06

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2016

Fixed in r261667.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld
Projects
None yet
Development

No branches or pull requests

2 participants