brintos

brintos / llvm-project-archived public Read only

0
0
Text · 15.2 KiB · 54f7d9b Raw
451 lines · yaml
1## Show that when "DATA" is used with an address, it forces the found location2## to be symbolized as data, including the source information.3 4# RUN: yaml2obj %s -o %t.so5 6# RUN: llvm-symbolizer 'DATA 0x304d0' 'DATA 0x304d1' 'DATA 0x304d3' \7# RUN:   'DATA 0x304c0' 'DATA 0x304c8' 'DATA 0x304d4' 'DATA 0x304dc' \8# RUN:   'DATA 0x304d8' --obj=%t.so | FileCheck %s9 10# CHECK:      bss_global11# CHECK-NEXT: {{[0-9]+}} 412# CHECK-NEXT: /tmp/file.cpp:113# CHECK-EMPTY:14 15## Check that lookups in the middle of the symbol are also resolved correctly.16# CHECK:      bss_global17# CHECK-NEXT: {{[0-9]+}} 418# CHECK-NEXT: /tmp/file.cpp:119# CHECK-EMPTY:20# CHECK:      bss_global21# CHECK-NEXT: {{[0-9]+}} 422# CHECK-NEXT: /tmp/file.cpp:123# CHECK-EMPTY:24 25## Now, the remainder of the symbols.26# CHECK-NEXT: data_global27# CHECK-NEXT: {{[0-9]+}} 428# CHECK-NEXT: /tmp/file.cpp:229# CHECK-EMPTY:30# CHECK-NEXT: str31# CHECK-NEXT: {{[0-9]+}} 832# CHECK-NEXT: /tmp/file.cpp:433# CHECK-EMPTY:34# CHECK-NEXT: f()::function_global35# CHECK-NEXT: {{[0-9]+}} 436# CHECK-NEXT: /tmp/file.cpp:837# CHECK-EMPTY:38 39## Including the one that includes an addend.40# CHECK-NEXT: alpha41# CHECK-NEXT: {{[0-9]+}} 442# CHECK-NEXT: /tmp/file.cpp:1243# CHECK-EMPTY:44# CHECK-NEXT: beta45# CHECK-NEXT: {{[0-9]+}} 446# CHECK-NEXT: /tmp/file.cpp:1347# CHECK-EMPTY:48 49## Ensure there's still a global that's offset-based.50# RUN: llvm-dwarfdump --debug-info %t.so | FileCheck %s --check-prefix=OFFSET51 52# OFFSET: DW_AT_location (DW_OP_addrx 0x4, DW_OP_plus_uconst 0x4)53 54################################################################################55## File below was generated using:56##57##   $ clang++ -g -O3 /tmp/file.cpp -shared -fuse-ld=lld -nostdlib \58##     -target aarch64-linux-gnuabi -mllvm -global-merge-ignore-single-use \59##     -o /tmp/file.so60##61##  With /tmp/file.cpp as:62##    1: int bss_global;63##    2: int data_global = 2;64##    3:65##    4: const char* str =66##    5:     "12345678";67##    6:68##    7: int* f() {69##    8:   static int function_global;70##    9:   return &function_global;71##   10: }72##   11:73##   12: static int alpha;74##   13: static int beta;75##   14: int *f(bool b) { return beta ? &alpha : &beta; }76##   15:77##78## ... then, one can get the offsets using `nm`, like:79##   $ nm out.so | grep bss_global80##     00000000000038fc B bss_global81##82## Note the use of the aarch64 target (with -nostdlib in order to allow linkage83## without libraries for cross-compilation) as well as -O3 and84## -global-merge-ignore-single-use. This is a specific combination that makes85## the compiler emit the `alpha` global variable with a more complex86## DW_AT_location than just a DW_OP_addr/DW_OP_addrx. In this instance, it87## outputs a `DW_AT_location  (DW_OP_addrx 0x4, DW_OP_plus_uconst 0x4)`.88##89## Ideally, this would be tested by invoking clang directly on a C source file,90## but unfortunately there's no way to do that for LLVM tests. The other option91## is to compile IR to an objfile, but llvm-symbolizer doesn't understand that92## two symbols can have the same address in different sections. In the code93## above, for example, we'd have bss_global at .bss+0x0, and data_global at94## .data+0x0, and so the symbolizer would only print one of them. Hence, we have95## the ugly dso-to-yaml blob below.96##97## For now, constant strings don't have a debuginfo entry, and so can't be98## symbolized correctly. In future (if D123534 gets merged), this can be updated99## to include a check that llvm-symbolizer can also symbolize constant strings,100## like `str` above (basically that &"12345678" should be symbolizable)101## to the specific line. Then, you can find the address of the constant string102## from the relocation:103##104##   $ nm out.so | grep str105##     00000000000038c0 D str106##   $ llvm-objdump -R out.so | grep 38c0107##     00000000000038c0 R_X86_64_RELATIVE *ABS*+0x4f8 # <-- 0x4f8108################################################################################109 110--- !ELF111FileHeader:112  Class:           ELFCLASS64113  Data:            ELFDATA2LSB114  Type:            ET_DYN115  Machine:         EM_AARCH64116ProgramHeaders:117  - Type:            PT_PHDR118    Flags:           [ PF_R ]119    VAddr:           0x40120    Align:           0x8121  - Type:            PT_LOAD122    Flags:           [ PF_R ]123    FirstSec:        .dynsym124    LastSec:         .eh_frame125    Align:           0x10000126  - Type:            PT_LOAD127    Flags:           [ PF_X, PF_R ]128    FirstSec:        .text129    LastSec:         .text130    VAddr:           0x103E4131    Align:           0x10000132  - Type:            PT_LOAD133    Flags:           [ PF_W, PF_R ]134    FirstSec:        .dynamic135    LastSec:         .dynamic136    VAddr:           0x20410137    Align:           0x10000138  - Type:            PT_LOAD139    Flags:           [ PF_W, PF_R ]140    FirstSec:        .data141    LastSec:         .bss142    VAddr:           0x304C0143    Align:           0x10000144  - Type:            PT_DYNAMIC145    Flags:           [ PF_W, PF_R ]146    FirstSec:        .dynamic147    LastSec:         .dynamic148    VAddr:           0x20410149    Align:           0x8150  - Type:            PT_GNU_RELRO151    Flags:           [ PF_R ]152    FirstSec:        .dynamic153    LastSec:         .dynamic154    VAddr:           0x20410155  - Type:            PT_GNU_EH_FRAME156    Flags:           [ PF_R ]157    FirstSec:        .eh_frame_hdr158    LastSec:         .eh_frame_hdr159    VAddr:           0x37C160    Align:           0x4161  - Type:            PT_GNU_STACK162    Flags:           [ PF_W, PF_R ]163    Align:           0x0164Sections:165  - Name:            .dynsym166    Type:            SHT_DYNSYM167    Flags:           [ SHF_ALLOC ]168    Address:         0x238169    Link:            .dynstr170    AddressAlign:    0x8171  - Name:            .gnu.hash172    Type:            SHT_GNU_HASH173    Flags:           [ SHF_ALLOC ]174    Address:         0x2C8175    Link:            .dynsym176    AddressAlign:    0x8177    Header:178      SymNdx:          0x1179      Shift2:          0x1A180    BloomFilter:     [ 0x400188002180000C ]181    HashBuckets:     [ 0x1 ]182    HashValues:      [ 0xEE8502A, 0xEE85016, 0xC033991C, 0x61F7372E, 0xB88AB7F ]183  - Name:            .hash184    Type:            SHT_HASH185    Flags:           [ SHF_ALLOC ]186    Address:         0x2F8187    Link:            .dynsym188    AddressAlign:    0x4189    Bucket:          [ 5, 0, 4, 0, 3, 0 ]190    Chain:           [ 0, 0, 0, 1, 2, 0 ]191  - Name:            .dynstr192    Type:            SHT_STRTAB193    Flags:           [ SHF_ALLOC ]194    Address:         0x330195    AddressAlign:    0x1196  - Name:            .rela.dyn197    Type:            SHT_RELA198    Flags:           [ SHF_ALLOC ]199    Address:         0x358200    Link:            .dynsym201    AddressAlign:    0x8202    Relocations:203      - Offset:          0x304C8204        Type:            R_AARCH64_RELATIVE205        Addend:          880206  - Name:            .rodata207    Type:            SHT_PROGBITS208    Flags:           [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]209    Address:         0x370210    AddressAlign:    0x1211    EntSize:         0x1212    Content:         '313233343536373800'213  - Name:            .eh_frame_hdr214    Type:            SHT_PROGBITS215    Flags:           [ SHF_ALLOC ]216    Address:         0x37C217    AddressAlign:    0x4218    Content:         011B033B18000000020000006800010034000000740001004C000000219  - Name:            .eh_frame220    Type:            SHT_PROGBITS221    Flags:           [ SHF_ALLOC ]222    Address:         0x398223    AddressAlign:    0x8224    Content:         1400000000000000017A5200017C1E011B0C1F0000000000140000001C0000002C0001000C00000000000000000000001400000034000000200001001C000000000000000000000000000000225  - Name:            .text226    Type:            SHT_PROGBITS227    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]228    Address:         0x103E4229    AddressAlign:    0x4230    Content:         0001009000501391C0035FD60801009008611391E90308AA2A4540B85F0100710001899AC0035FD6231  - Name:            .dynamic232    Type:            SHT_DYNAMIC233    Flags:           [ SHF_WRITE, SHF_ALLOC ]234    Address:         0x20410235    Link:            .dynstr236    AddressAlign:    0x8237    Entries:238      - Tag:             DT_RELA239        Value:           0x358240      - Tag:             DT_RELASZ241        Value:           0x18242      - Tag:             DT_RELAENT243        Value:           0x18244      - Tag:             DT_RELACOUNT245        Value:           0x1246      - Tag:             DT_SYMTAB247        Value:           0x238248      - Tag:             DT_SYMENT249        Value:           0x18250      - Tag:             DT_STRTAB251        Value:           0x330252      - Tag:             DT_STRSZ253        Value:           0x28254      - Tag:             DT_GNU_HASH255        Value:           0x2C8256      - Tag:             DT_HASH257        Value:           0x2F8258      - Tag:             DT_NULL259        Value:           0x0260  - Name:            .data261    Type:            SHT_PROGBITS262    Flags:           [ SHF_WRITE, SHF_ALLOC ]263    Address:         0x304C0264    AddressAlign:    0x8265    Content:         '02000000000000000000000000000000'266  - Name:            .bss267    Type:            SHT_NOBITS268    Flags:           [ SHF_WRITE, SHF_ALLOC ]269    Address:         0x304D0270    AddressAlign:    0x4271    Size:            0x10272  - Name:            .debug_abbrev273    Type:            SHT_PROGBITS274    AddressAlign:    0x1275    Content:         011101252513050325721710171B25111B120673170000023400032549133F193A0B3B0B0218000003240003253E0B0B0B0000040F004913000005260049130000062E01111B120640187A196E2503253A0B3B0B49133F190000073400032549133A0B3B0B02180000083400032549133A0B3B0B02186E25000009050003253A0B3B0B4913000000276  - Name:            .debug_info277    Type:            SHT_PROGBITS278    AddressAlign:    0x1279    Content:         AB0000000500010800000000010021000108000000000000000205280000000800000002032E000000000102A1000304050402052E000000000202A101020648000000000402A102044D00000005520000000307080106050C000000016F0D0E0007A500000007082E000000000802A1030008092E000000000D02A1040A080B2E000000000C04A10423040C06061C000000016F0F0E000EA50000000910000EAA00000000042E0000000311020100280  - Name:            .debug_str_offsets281    Type:            SHT_PROGBITS282    AddressAlign:    0x1283    Content:         4C00000005000000A2000000000000002C00000059000000280000001C00000072000000640000008C0000008700000069000000140000007B0000009C0000001A0000000E0000008500000076000000284  - Name:            .comment285    Type:            SHT_PROGBITS286    Flags:           [ SHF_MERGE, SHF_STRINGS ]287    AddressAlign:    0x1288    EntSize:         0x1289    Content:         4C696E6B65723A204C4C442031352E302E300000636C616E672076657273696F6E2031352E302E30202868747470733A2F2F6769746875622E636F6D2F6C6C766D2F6C6C766D2D70726F6A6563742E67697420306462616566363162353666306566306162306366333865613932666663316633356265653366662900290  - Name:            .debug_line291    Type:            SHT_PROGBITS292    AddressAlign:    0x1293    Content:         620000000500080037000000010101FB0E0D00010101010000000100000101011F010E00000003011F020F051E0100000000006C97BBE59F7DC6A9EA956633431DA63E0400000902E4030100000000001805030A140500BF05190A0105120608740204000101294  - Name:            .debug_line_str295    Type:            SHT_PROGBITS296    Flags:           [ SHF_MERGE, SHF_STRINGS ]297    AddressAlign:    0x1298    EntSize:         0x1299    Content:         2F746D702F66696C652E637070002F7573722F6C6F63616C2F676F6F676C652F686F6D652F6D69746368702F6C6C766D2D6275696C642F6F707400300Symbols:301  - Name:            file.cpp302    Type:            STT_FILE303    Index:           SHN_ABS304  - Name:            '$x.0'305    Section:         .text306    Value:           0x103E4307  - Name:            _ZZ1fvE15function_global308    Type:            STT_OBJECT309    Section:         .bss310    Value:           0x304D4311    Size:            0x4312  - Name:            '$d.1'313    Section:         .bss314    Value:           0x304D0315  - Name:            '$d.2'316    Section:         .data317    Value:           0x304C0318  - Name:            '$d.3'319    Section:         .rodata320    Value:           0x370321  - Name:            '$d.4'322    Section:         .debug_abbrev323  - Name:            '$d.5'324    Section:         .debug_info325  - Name:            '$d.6'326    Section:         .debug_str_offsets327  - Name:            '$d.7'328    Section:         .debug_str329    Value:           0xA2330  - Name:            '$d.8'331    Section:         .debug_addr332  - Name:            _ZL4beta333    Type:            STT_OBJECT334    Section:         .bss335    Value:           0x304D8336    Size:            0x4337  - Name:            _ZL5alpha338    Type:            STT_OBJECT339    Section:         .bss340    Value:           0x304DC341    Size:            0x4342  - Name:            '$d.9'343    Section:         .comment344    Value:           0x13345  - Name:            '$d.10'346    Section:         .eh_frame347    Value:           0x398348  - Name:            '$d.11'349    Section:         .debug_line350  - Name:            '$d.12'351    Section:         .debug_line_str352    Value:           0xE353  - Name:            _DYNAMIC354    Section:         .dynamic355    Value:           0x20410356    Other:           [ STV_HIDDEN ]357  - Name:            _Z1fv358    Type:            STT_FUNC359    Section:         .text360    Binding:         STB_GLOBAL361    Value:           0x103E4362    Size:            0xC363  - Name:            _Z1fb364    Type:            STT_FUNC365    Section:         .text366    Binding:         STB_GLOBAL367    Value:           0x103F0368    Size:            0x1C369  - Name:            bss_global370    Type:            STT_OBJECT371    Section:         .bss372    Binding:         STB_GLOBAL373    Value:           0x304D0374    Size:            0x4375  - Name:            data_global376    Type:            STT_OBJECT377    Section:         .data378    Binding:         STB_GLOBAL379    Value:           0x304C0380    Size:            0x4381  - Name:            str382    Type:            STT_OBJECT383    Section:         .data384    Binding:         STB_GLOBAL385    Value:           0x304C8386    Size:            0x8387DynamicSymbols:388  - Name:            _Z1fv389    Type:            STT_FUNC390    Section:         .text391    Binding:         STB_GLOBAL392    Value:           0x103E4393    Size:            0xC394  - Name:            _Z1fb395    Type:            STT_FUNC396    Section:         .text397    Binding:         STB_GLOBAL398    Value:           0x103F0399    Size:            0x1C400  - Name:            bss_global401    Type:            STT_OBJECT402    Section:         .bss403    Binding:         STB_GLOBAL404    Value:           0x304D0405    Size:            0x4406  - Name:            data_global407    Type:            STT_OBJECT408    Section:         .data409    Binding:         STB_GLOBAL410    Value:           0x304C0411    Size:            0x4412  - Name:            str413    Type:            STT_OBJECT414    Section:         .data415    Binding:         STB_GLOBAL416    Value:           0x304C8417    Size:            0x8418DWARF:419  debug_str:420    - '/tmp/file.cpp'421    - _Z1fb422    - alpha423    - f424    - data_global425    - int426    - '/usr/local/google/home/mitchp/llvm-build/opt'427    - bss_global428    - char429    - _ZL4beta430    - str431    - bool432    - _ZL5alpha433    - b434    - beta435    - function_global436    - _Z1fv437    - 'clang version 15.0.0 (https://github.com/llvm/llvm-project.git 0dbaef61b56f0ef0ab0cf38ea92ffc1f35bee3ff)'438  debug_addr:439    - Length:          0x3C440      Version:         0x5441      AddressSize:     0x8442      Entries:443        - Address:         0x304D0444        - Address:         0x304C0445        - Address:         0x304C8446        - Address:         0x304D4447        - Address:         0x304D8448        - Address:         0x103E4449        - Address:         0x103F0450...451