1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-11 05:46:58 +03:00
This commit is contained in:
Rui Ueyama 2021-02-27 12:08:55 +09:00
parent 31008f5cb2
commit e23c358deb
5 changed files with 25 additions and 22 deletions

View File

@ -44,27 +44,27 @@ static void overflow_check(InputSection *sec, Symbol &sym, u64 r_type, u64 val)
switch (r_type) { switch (r_type) {
case R_X86_64_8: case R_X86_64_8:
if (val != (u8)val) if (val != (u8)val)
Error() << *sec << ": relocation R_X86_64_8 against " << sym.name Error() << *sec << ": relocation R_X86_64_8 against " << sym
<< " out of range: " << val << " is not in [0, 255]"; << " out of range: " << val << " is not in [0, 255]";
return; return;
case R_X86_64_PC8: case R_X86_64_PC8:
if (val != (i8)val) if (val != (i8)val)
Error() << *sec << ": relocation R_X86_64_PC8 against " << sym.name Error() << *sec << ": relocation R_X86_64_PC8 against " << sym
<< " out of range: " << (i64)val << " is not in [-128, 127]"; << " out of range: " << (i64)val << " is not in [-128, 127]";
return; return;
case R_X86_64_16: case R_X86_64_16:
if (val != (u16)val) if (val != (u16)val)
Error() << *sec << ": relocation R_X86_64_16 against " << sym.name Error() << *sec << ": relocation R_X86_64_16 against " << sym
<< " out of range: " << val << " is not in [0, 65535]"; << " out of range: " << val << " is not in [0, 65535]";
return; return;
case R_X86_64_PC16: case R_X86_64_PC16:
if (val != (i16)val) if (val != (i16)val)
Error() << *sec << ": relocation R_X86_64_PC16 against " << sym.name Error() << *sec << ": relocation R_X86_64_PC16 against " << sym
<< " out of range: " << (i64)val << " is not in [-32768, 32767]"; << " out of range: " << (i64)val << " is not in [-32768, 32767]";
return; return;
case R_X86_64_32: case R_X86_64_32:
if (val != (u32)val) if (val != (u32)val)
Error() << *sec << ": relocation R_X86_64_32 against " << sym.name Error() << *sec << ": relocation R_X86_64_32 against " << sym
<< " out of range: " << val << " is not in [0, 4294967296]"; << " out of range: " << val << " is not in [0, 4294967296]";
return; return;
case R_X86_64_32S: case R_X86_64_32S:
@ -82,8 +82,8 @@ static void overflow_check(InputSection *sec, Symbol &sym, u64 r_type, u64 val)
case R_X86_64_GOTTPOFF: case R_X86_64_GOTTPOFF:
if (val != (i32)val) if (val != (i32)val)
Error() << *sec << ": relocation " << rel_to_string(r_type) Error() << *sec << ": relocation " << rel_to_string(r_type)
<< " against " << sym.name << " out of range: " << " against " << sym << " out of range: " << (i64)val
<< (i64)val << " is not in [-2147483648, 2147483647]"; << " is not in [-2147483648, 2147483647]";
return; return;
case R_X86_64_NONE: case R_X86_64_NONE:
case R_X86_64_64: case R_X86_64_64:
@ -277,7 +277,7 @@ void InputSection::apply_reloc_nonalloc(u8 *base) {
Symbol &sym = *file->symbols[rel.r_sym]; Symbol &sym = *file->symbols[rel.r_sym];
if (!sym.file || sym.is_placeholder) { if (!sym.file || sym.is_placeholder) {
Error() << "undefined symbol: " << *file << ": " << sym.name; Error() << "undefined symbol: " << *file << ": " << sym;
continue; continue;
} }
@ -361,7 +361,7 @@ void InputSection::scan_relocations() {
bool is_code = (sym.st_type == STT_FUNC); bool is_code = (sym.st_type == STT_FUNC);
if (!sym.file || sym.is_placeholder) { if (!sym.file || sym.is_placeholder) {
Error() << "undefined symbol: " << *file << ": " << sym.name; Error() << "undefined symbol: " << *file << ": " << sym;
continue; continue;
} }
@ -369,7 +369,7 @@ void InputSection::scan_relocations() {
auto error = [&]() { auto error = [&]() {
Error() << *this << ": " << rel_to_string(rel.r_type) Error() << *this << ": " << rel_to_string(rel.r_type)
<< " relocation against symbol `" << sym.name << " relocation against symbol `" << sym
<< "' can not be used; recompile with -fPIE"; << "' can not be used; recompile with -fPIE";
}; };
@ -489,7 +489,7 @@ void InputSection::scan_relocations() {
if (i + 1 == rels.size() || rels[i + 1].r_type != R_X86_64_PLT32) if (i + 1 == rels.size() || rels[i + 1].r_type != R_X86_64_PLT32)
Error() << *this << ": TLSLD reloc not followed by PLT32"; Error() << *this << ": TLSLD reloc not followed by PLT32";
if (sym.is_imported()) if (sym.is_imported())
Error() << *this << ": TLSLD reloc refers external symbol " << sym.name; Error() << *this << ": TLSLD reloc refers external symbol " << sym;
if (config.relax) { if (config.relax) {
rel_types[i] = R_TLSLD_RELAX_LE; rel_types[i] = R_TLSLD_RELAX_LE;
@ -502,7 +502,7 @@ void InputSection::scan_relocations() {
case R_X86_64_DTPOFF32: case R_X86_64_DTPOFF32:
case R_X86_64_DTPOFF64: case R_X86_64_DTPOFF64:
if (sym.is_imported()) if (sym.is_imported())
Error() << *this << ": DTPOFF reloc refers external symbol " << sym.name; Error() << *this << ": DTPOFF reloc refers external symbol " << sym;
rel_types[i] = config.relax ? R_TPOFF : R_DTPOFF; rel_types[i] = config.relax ? R_TPOFF : R_DTPOFF;
break; break;
case R_X86_64_TPOFF32: case R_X86_64_TPOFF32:

View File

@ -305,7 +305,7 @@ static void check_duplicate_symbols() {
if (esym.is_defined() && !is_weak && !is_eliminated && sym.file != file) if (esym.is_defined() && !is_weak && !is_eliminated && sym.file != file)
Error() << "duplicate symbol: " << *file << ": " << *sym.file Error() << "duplicate symbol: " << *file << ": " << *sym.file
<< ": " << sym.name; << ": " << sym;
} }
}); });

5
mold.h
View File

@ -299,6 +299,11 @@ public:
u8 has_copyrel : 1 = false; u8 has_copyrel : 1 = false;
}; };
inline std::ostream &operator<<(std::ostream &out, const Symbol &sym) {
out << sym.name;
return out;
}
// //
// input_sections.cc // input_sections.cc
// //

View File

@ -537,7 +537,7 @@ void ObjectFile::maybe_override_symbol(Symbol &sym, i64 symidx) {
bool is_weak = (esym.st_bind == STB_WEAK); bool is_weak = (esym.st_bind == STB_WEAK);
SyncOut() << "trace: " << *sym.file SyncOut() << "trace: " << *sym.file
<< (is_weak ? ": weak definition of " : ": definition of ") << (is_weak ? ": weak definition of " : ": definition of ")
<< sym.name; << sym;
} }
} }
} }
@ -561,8 +561,7 @@ void ObjectFile::resolve_symbols() {
sym.is_placeholder = true; sym.is_placeholder = true;
if (sym.traced) if (sym.traced)
SyncOut() << "trace: " << *sym.file SyncOut() << "trace: " << *sym.file << ": lazy definition of " << sym;
<< ": lazy definition of " << sym.name;
} }
} else { } else {
maybe_override_symbol(sym, i); maybe_override_symbol(sym, i);
@ -584,7 +583,7 @@ void ObjectFile::mark_live_objects(std::function<void(ObjectFile *)> feeder) {
} }
if (sym.traced) if (sym.traced)
SyncOut() << "trace: " << *this << ": reference to " << sym.name; SyncOut() << "trace: " << *this << ": reference to " << sym;
if (esym.st_bind != STB_WEAK && sym.file && !sym.file->is_alive.exchange(true)) { if (esym.st_bind != STB_WEAK && sym.file && !sym.file->is_alive.exchange(true)) {
if (!sym.file->is_dso) if (!sym.file->is_dso)
@ -592,7 +591,7 @@ void ObjectFile::mark_live_objects(std::function<void(ObjectFile *)> feeder) {
if (sym.traced) if (sym.traced)
SyncOut() << "trace: " << *this << " keeps " << *sym.file SyncOut() << "trace: " << *this << " keeps " << *sym.file
<< " for " << sym.name; << " for " << sym;
} }
} }
} }
@ -617,8 +616,7 @@ void ObjectFile::handle_undefined_weak_symbols() {
sym.is_placeholder = false; sym.is_placeholder = false;
if (sym.traced) if (sym.traced)
SyncOut() << "trace: " << *this << ": unresolved weak symbol " SyncOut() << "trace: " << *this << ": unresolved weak symbol " << sym;
<< sym.name;
} }
} }
} }
@ -958,7 +956,7 @@ void SharedFile::resolve_symbols() {
bool is_weak = (esym.st_bind == STB_WEAK); bool is_weak = (esym.st_bind == STB_WEAK);
SyncOut() << "trace: " << *sym.file SyncOut() << "trace: " << *sym.file
<< (is_weak ? ": weak definition of " : ": definition of ") << (is_weak ? ": weak definition of " : ": definition of ")
<< sym.name; << sym;
} }
} }
} }

View File

@ -999,7 +999,7 @@ u64 EhFrameSection::get_addr(const Symbol &sym) {
} }
} }
Fatal() << file << ": .eh_frame has bad symbol: " << sym.name; Fatal() << file << ": .eh_frame has bad symbol: " << sym;
} }
void CopyrelSection::add_symbol(Symbol *sym) { void CopyrelSection::add_symbol(Symbol *sym) {