LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 26712 - PHDR & section mismatch in lld-linked static hello world on FreeBSD results in segfault
Summary: PHDR & section mismatch in lld-linked static hello world on FreeBSD results i...
Status: RESOLVED FIXED
Alias: None
Product: lld
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: unspecified
Hardware: PC FreeBSD
: P normal
Assignee: Rafael Ávila de Espíndola
URL:
Keywords:
Depends on:
Blocks: 23214
  Show dependency tree
 
Reported: 2016-02-23 08:03 PST by emaste
Modified: 2016-02-23 12:40 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description emaste 2016-02-23 08:03:39 PST
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
Comment 1 Rafael Ávila de Espíndola 2016-02-23 12:40:53 PST
Fixed in r261667.