xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/add-symbol-new-symtab.test (revision ee142c4988f491f3eef0f28739e6e99867912731)
1afd81a63SGeorgy Komarov## Show that llvm-objcopy can replace the symbol table with a new one.
2afd81a63SGeorgy Komarov
3afd81a63SGeorgy Komarov# RUN: yaml2obj %s -o %t
4afd81a63SGeorgy Komarov
5afd81a63SGeorgy Komarov# RUN: llvm-objcopy -R .symtab --add-symbol newsym=1234 %t %t2
6afd81a63SGeorgy Komarov# RUN: llvm-readelf -S -s %t2 | FileCheck %s --match-full-lines
7afd81a63SGeorgy Komarov
8afd81a63SGeorgy Komarov# CHECK: There are 5 section headers, starting at offset {{.+}}:
9afd81a63SGeorgy Komarov# CHECK:      [Nr] Name      Type     Address          Off    Size   ES  Flg Lk Inf Al
10afd81a63SGeorgy Komarov# CHECK-NEXT: [ 0]           NULL     0000000000000000 {{.+}} 000000 00      0  0   0
11afd81a63SGeorgy Komarov# CHECK-NEXT: [ 1] .text     PROGBITS 0000000000001000 {{.+}} 000040 00  AX  0  0   16
12afd81a63SGeorgy Komarov# CHECK-NEXT: [ 2] .strtab   STRTAB   0000000000000000 {{.+}} 000001 00      0  0   1
13afd81a63SGeorgy Komarov# CHECK-NEXT: [ 3] .shstrtab STRTAB   0000000000000000 {{.+}} 000028 00      0  0   1
14afd81a63SGeorgy Komarov# CHECK-NEXT: [ 4] .symtab   SYMTAB   0000000000000000 {{.+}} 000030 18      3  1   8
15afd81a63SGeorgy Komarov
16afd81a63SGeorgy Komarov# CHECK: Symbol table '.symtab' contains 2 entries:
17afd81a63SGeorgy Komarov# CHECK-NEXT:   Num:    Value          Size Type    Bind   Vis       Ndx Name
18afd81a63SGeorgy Komarov# CHECK-NEXT:     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND
19afd81a63SGeorgy Komarov# CHECK-NEXT:     1: 00000000000004d2     0 NOTYPE  GLOBAL DEFAULT   ABS newsym
20afd81a63SGeorgy Komarov
21*ee142c49SFangrui Song## --set-section-flags works for newly created .symtab, which GNU objcopy does not do.
22*ee142c49SFangrui Song# RUN: llvm-objcopy -R .symtab --add-symbol newsym=1234 --set-section-flags .symtab=readonly,exclude %t %t3
23*ee142c49SFangrui Song# RUN: llvm-readelf -S %t3 | FileCheck %s --check-prefix=CHECK2
24*ee142c49SFangrui Song
25*ee142c49SFangrui Song# CHECK2:     [ 4] .symtab   SYMTAB   0000000000000000 {{.+}} 000030 18  E   3  1   8
26*ee142c49SFangrui Song
27afd81a63SGeorgy Komarov--- !ELF
28afd81a63SGeorgy KomarovFileHeader:
29afd81a63SGeorgy Komarov  Class:   ELFCLASS64
30afd81a63SGeorgy Komarov  Data:    ELFDATA2LSB
31afd81a63SGeorgy Komarov  Type:    ET_DYN
32afd81a63SGeorgy Komarov  Machine: EM_X86_64
33afd81a63SGeorgy KomarovSections:
34afd81a63SGeorgy Komarov  - Name:            .text
35afd81a63SGeorgy Komarov    Type:            SHT_PROGBITS
36afd81a63SGeorgy Komarov    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
37afd81a63SGeorgy Komarov    Address:         0x1000
38afd81a63SGeorgy Komarov    AddressAlign:    0x0000000000000010
39afd81a63SGeorgy Komarov    Size:            64
40afd81a63SGeorgy KomarovSymbols:
41afd81a63SGeorgy Komarov  - Name:     foo
42afd81a63SGeorgy Komarov    Type:     STT_FUNC
43afd81a63SGeorgy Komarov    Section:  .text
44afd81a63SGeorgy Komarov    Value:    0x1000
45afd81a63SGeorgy Komarov    Size:     8
46afd81a63SGeorgy Komarov  - Name:     bar
47afd81a63SGeorgy Komarov    Type:     STT_FUNC
48afd81a63SGeorgy Komarov    Section:  .text
49afd81a63SGeorgy Komarov    Value:    0x1008
50afd81a63SGeorgy Komarov    Size:     8
51afd81a63SGeorgy Komarov  - Name:     baz
52afd81a63SGeorgy Komarov    Type:     STT_FUNC
53afd81a63SGeorgy Komarov    Section:  .text
54afd81a63SGeorgy Komarov    Value:    0x1010
55afd81a63SGeorgy Komarov    Size:     8
56afd81a63SGeorgy Komarov
57