Skip to content

Commit 03e8433

Browse files
committed
elf2rel: improve error handling
1 parent dd63995 commit 03e8433

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ttyd-tools/elf2rel/elf2rel.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ const std::vector<std::string> cRelSectionMask = {
106106
int main(int argc, char **argv)
107107
{
108108
if (argc <= 2)
109+
{
110+
printf("Usage: %s <elf file> <symbol file>", argv[0]);
109111
return 1;
112+
}
110113

111114
std::string elfFilename = argv[1];
112115
std::string lstFilename = argv[2];
@@ -115,14 +118,14 @@ int main(int argc, char **argv)
115118
ELFIO::elfio inputElf;
116119
if (!inputElf.load(elfFilename))
117120
{
121+
printf("Failed to load input file");
118122
return 1;
119123
}
120124

121125
auto externalSymbolMap = loadSymbolMap(lstFilename);
122126

123127
// Find special sections
124128
ELFIO::section *symSection = nullptr;
125-
ELFIO::section *strSection = nullptr;
126129
std::vector<ELFIO::section *> relocationSections;
127130
for (const auto &section : inputElf.sections)
128131
{
@@ -280,8 +283,8 @@ int main(int argc, char **argv)
280283
if (!symbols.get_symbol(symbol, symbolName, symbolValue,
281284
size, bind, symbolType, sectionIndex, other))
282285
{
283-
// #todo-elf2rel: Proper error handling
284-
return -1;
286+
printf("Unable to find symbol %u in symbol table!", static_cast<uint32_t>(symbol));
287+
return 1;
285288
}
286289

287290
// Add relocation to list

0 commit comments

Comments
 (0)