llvm.org GIT mirror llvm / dba0706
Compute correct symbol sizes for MachO and COFF. Before this would dump from the symbol start to the end of the section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240367 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
2 changed file(s) with 53 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 // RUN: llvm-mc %s -o %t -filetype=obj -triple=x86_64-pc-win32
1 // RUN: llvm-cxxdump %t | FileCheck %s
2
3 // CHECK: ??_8B@@7B@[0]: 8
4 // CHECK-NEXT: ??_8B@@7B@[4]: 9
5 // CHECK-NEXT: ??_8C@@7B@[0]: 10
6 // CHECK-NEXT: ??_8C@@7B@[4]: 11
7 // CHECK-NEXT: ??_8D@@7B0@@[0]: 0
8 // CHECK-NEXT: ??_8D@@7B0@@[4]: 1
9 // CHECK-NEXT: ??_8D@@7B0@@[8]: 2
10 // CHECK-NEXT: ??_8D@@7B0@@[12]: 3
11 // CHECK-NEXT: ??_8D@@7BB@@@[0]: 4
12 // CHECK-NEXT: ??_8D@@7BB@@@[4]: 5
13 // CHECK-NEXT: ??_8D@@7BC@@@[0]: 6
14 // CHECK-NEXT: ??_8D@@7BC@@@[4]: 7
15
16 .section .rdata,"dr"
17 .globl "??_8D@@7B0@@"
18 "??_8D@@7B0@@":
19 .long 0
20 .long 1
21 .long 2
22 .long 3
23
24 .globl "??_8D@@7BB@@@"
25 "??_8D@@7BB@@@":
26 .long 4
27 .long 5
28
29 .globl "??_8D@@7BC@@@"
30 "??_8D@@7BC@@@":
31 .long 6
32 .long 7
33
34 .globl "??_8B@@7B@"
35 "??_8B@@7B@":
36 .long 8
37 .long 9
38
39 .globl "??_8C@@7B@"
40 "??_8C@@7B@":
41 .long 10
42 .long 11
43
1515 #include "llvm/ADT/ArrayRef.h"
1616 #include "llvm/Object/Archive.h"
1717 #include "llvm/Object/ObjectFile.h"
18 #include "llvm/Object/SymbolSize.h"
1819 #include "llvm/Support/Debug.h"
1920 #include "llvm/Support/Endian.h"
2021 #include "llvm/Support/FileSystem.h"
186187
187188 uint8_t BytesInAddress = Obj->getBytesInAddress();
188189
189 for (const object::SymbolRef &Sym : Obj->symbols()) {
190 ErrorOr>> SymAddrOrErr =
191 object::computeSymbolSizes(*Obj);
192 if (error(SymAddrOrErr.getError()))
193 return;
194
195 for (auto &P : *SymAddrOrErr) {
196 object::SymbolRef Sym = P.first;
197 uint64_t SymSize = P.second;
190198 StringRef SymName;
191199 if (error(Sym.getName(SymName)))
192200 return;
206214 uint64_t SymAddress;
207215 if (error(Sym.getAddress(SymAddress)))
208216 return;
209 uint64_t SymSize = Sym.getSize();
210217 uint64_t SecAddress = Sec.getAddress();
211218 uint64_t SecSize = Sec.getSize();
212219 uint64_t SymOffset = SymAddress - SecAddress;