Skip to content

Commit 8103294

Browse files
committedJul 17, 2015
[llvm-cxxdump] Don't rely on global state
Differential Revision: http://reviews.llvm.org/D11227 llvm-svn: 242509
1 parent f8d14db commit 8103294

File tree

1 file changed

+18
-41
lines changed

1 file changed

+18
-41
lines changed
 

‎llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp

+18-41
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,24 @@ cl::list<std::string> InputFilenames(cl::Positional,
4040
cl::ZeroOrMore);
4141
} // namespace opts
4242

43-
static int ReturnValue = EXIT_SUCCESS;
44-
4543
namespace llvm {
4644

47-
static bool error(std::error_code EC) {
45+
static void error(std::error_code EC) {
4846
if (!EC)
49-
return false;
50-
51-
ReturnValue = EXIT_FAILURE;
47+
return;
5248
outs() << "\nError reading file: " << EC.message() << ".\n";
5349
outs().flush();
54-
return true;
50+
exit(1);
5551
}
5652

5753
} // namespace llvm
5854

5955
static void reportError(StringRef Input, StringRef Message) {
6056
if (Input == "-")
6157
Input = "<stdin>";
62-
6358
errs() << Input << ": " << Message << "\n";
6459
errs().flush();
65-
ReturnValue = EXIT_FAILURE;
60+
exit(1);
6661
}
6762

6863
static void reportError(StringRef Input, std::error_code EC) {
@@ -84,7 +79,7 @@ static SmallVectorImpl<SectionRef> &getRelocSections(const ObjectFile *Obj,
8479
return SectionRelocMap[Sec];
8580
}
8681

87-
static bool collectRelocatedSymbols(const ObjectFile *Obj,
82+
static void collectRelocatedSymbols(const ObjectFile *Obj,
8883
const SectionRef &Sec, uint64_t SecAddress,
8984
uint64_t SymAddress, uint64_t SymSize,
9085
StringRef *I, StringRef *E) {
@@ -98,19 +93,17 @@ static bool collectRelocatedSymbols(const ObjectFile *Obj,
9893
if (RelocSymI == Obj->symbol_end())
9994
continue;
10095
ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
101-
if (error(RelocSymName.getError()))
102-
return true;
96+
error(RelocSymName.getError());
10397
uint64_t Offset = Reloc.getOffset();
10498
if (Offset >= SymOffset && Offset < SymEnd) {
10599
*I = *RelocSymName;
106100
++I;
107101
}
108102
}
109103
}
110-
return false;
111104
}
112105

113-
static bool collectRelocationOffsets(
106+
static void collectRelocationOffsets(
114107
const ObjectFile *Obj, const SectionRef &Sec, uint64_t SecAddress,
115108
uint64_t SymAddress, uint64_t SymSize, StringRef SymName,
116109
std::map<std::pair<StringRef, uint64_t>, StringRef> &Collection) {
@@ -122,14 +115,12 @@ static bool collectRelocationOffsets(
122115
if (RelocSymI == Obj->symbol_end())
123116
continue;
124117
ErrorOr<StringRef> RelocSymName = RelocSymI->getName();
125-
if (error(RelocSymName.getError()))
126-
return true;
118+
error(RelocSymName.getError());
127119
uint64_t Offset = Reloc.getOffset();
128120
if (Offset >= SymOffset && Offset < SymEnd)
129121
Collection[std::make_pair(SymName, Offset - SymOffset)] = *RelocSymName;
130122
}
131123
}
132-
return false;
133124
}
134125

135126
static void dumpCXXData(const ObjectFile *Obj) {
@@ -191,12 +182,10 @@ static void dumpCXXData(const ObjectFile *Obj) {
191182
object::SymbolRef Sym = P.first;
192183
uint64_t SymSize = P.second;
193184
ErrorOr<StringRef> SymNameOrErr = Sym.getName();
194-
if (error(SymNameOrErr.getError()))
195-
return;
185+
error(SymNameOrErr.getError());
196186
StringRef SymName = *SymNameOrErr;
197187
object::section_iterator SecI(Obj->section_begin());
198-
if (error(Sym.getSection(SecI)))
199-
return;
188+
error(Sym.getSection(SecI));
200189
// Skip external symbols.
201190
if (SecI == Obj->section_end())
202191
continue;
@@ -205,11 +194,9 @@ static void dumpCXXData(const ObjectFile *Obj) {
205194
if (Sec.isBSS() || Sec.isVirtual())
206195
continue;
207196
StringRef SecContents;
208-
if (error(Sec.getContents(SecContents)))
209-
return;
197+
error(Sec.getContents(SecContents));
210198
ErrorOr<uint64_t> SymAddressOrErr = Sym.getAddress();
211-
if (error(SymAddressOrErr.getError()))
212-
return;
199+
error(SymAddressOrErr.getError());
213200
uint64_t SymAddress = *SymAddressOrErr;
214201
uint64_t SecAddress = Sec.getAddress();
215202
uint64_t SecSize = Sec.getSize();
@@ -239,9 +226,7 @@ static void dumpCXXData(const ObjectFile *Obj) {
239226
COL.Data = ArrayRef<little32_t>(
240227
reinterpret_cast<const little32_t *>(SymContents.data()), 3);
241228
StringRef *I = std::begin(COL.Symbols), *E = std::end(COL.Symbols);
242-
if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I,
243-
E))
244-
return;
229+
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
245230
COLs[SymName] = COL;
246231
}
247232
// Class hierarchy descriptors in the MS-ABI start with '??_R3'
@@ -250,9 +235,7 @@ static void dumpCXXData(const ObjectFile *Obj) {
250235
CHD.Data = ArrayRef<little32_t>(
251236
reinterpret_cast<const little32_t *>(SymContents.data()), 3);
252237
StringRef *I = std::begin(CHD.Symbols), *E = std::end(CHD.Symbols);
253-
if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I,
254-
E))
255-
return;
238+
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
256239
CHDs[SymName] = CHD;
257240
}
258241
// Class hierarchy descriptors in the MS-ABI start with '??_R2'
@@ -268,9 +251,7 @@ static void dumpCXXData(const ObjectFile *Obj) {
268251
BCD.Data = ArrayRef<little32_t>(
269252
reinterpret_cast<const little32_t *>(SymContents.data()) + 1, 5);
270253
StringRef *I = std::begin(BCD.Symbols), *E = std::end(BCD.Symbols);
271-
if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I,
272-
E))
273-
return;
254+
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
274255
BCDs[SymName] = BCD;
275256
}
276257
// Type descriptors in the MS-ABI start with '??_R0'
@@ -283,9 +264,7 @@ static void dumpCXXData(const ObjectFile *Obj) {
283264
TD.AlwaysZero = *reinterpret_cast<const little32_t *>(DataPtr);
284265
TD.MangledName = SymContents.drop_front(BytesInAddress * 2);
285266
StringRef *I = std::begin(TD.Symbols), *E = std::end(TD.Symbols);
286-
if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I,
287-
E))
288-
return;
267+
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
289268
TDs[SymName] = TD;
290269
}
291270
// Throw descriptors in the MS-ABI start with '_TI'
@@ -316,9 +295,7 @@ static void dumpCXXData(const ObjectFile *Obj) {
316295
CT.VirtualBaseAdjustmentOffset = DataPtr[4];
317296
CT.Size = DataPtr[5];
318297
StringRef *I = std::begin(CT.Symbols), *E = std::end(CT.Symbols);
319-
if (collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I,
320-
E))
321-
return;
298+
collectRelocatedSymbols(Obj, Sec, SecAddress, SymAddress, SymSize, I, E);
322299
CTs[SymName] = CT;
323300
}
324301
// Construction vtables in the Itanium ABI start with '_ZTT' or '__ZTT'.
@@ -569,5 +546,5 @@ int main(int argc, const char *argv[]) {
569546
std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
570547
dumpInput);
571548

572-
return ReturnValue;
549+
return EXIT_SUCCESS;
573550
}

0 commit comments

Comments
 (0)
Please sign in to comment.