File tree 4 files changed +34
-3
lines changed
4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -252,7 +252,19 @@ void SectionChunk::writeTo(uint8_t *Buf) const {
252
252
// Get the output section of the symbol for this relocation. The output
253
253
// section is needed to compute SECREL and SECTION relocations used in debug
254
254
// info.
255
- Defined *Sym = cast<Defined>(File->getSymbol (Rel.SymbolTableIndex ));
255
+ auto *Sym =
256
+ dyn_cast_or_null<Defined>(File->getSymbol (Rel.SymbolTableIndex ));
257
+ if (!Sym) {
258
+ if (isCodeView () || isDWARF ())
259
+ continue ;
260
+ // Symbols in early discarded sections are represented using null pointers,
261
+ // so we need to retrieve the name from the object file.
262
+ COFFSymbolRef Sym =
263
+ check (File->getCOFFObj ()->getSymbol (Rel.SymbolTableIndex ));
264
+ StringRef Name;
265
+ File->getCOFFObj ()->getSymbolName (Sym, Name);
266
+ fatal (" relocation against symbol in discarded section: " + Name);
267
+ }
256
268
Chunk *C = Sym->getChunk ();
257
269
OutputSection *OS = C ? C->getOutputSection () : nullptr ;
258
270
@@ -328,7 +340,8 @@ void SectionChunk::getBaserels(std::vector<Baserel> *Res) {
328
340
uint8_t Ty = getBaserelType (Rel);
329
341
if (Ty == IMAGE_REL_BASED_ABSOLUTE)
330
342
continue ;
331
- if (isa<DefinedAbsolute>(File->getSymbol (Rel.SymbolTableIndex )))
343
+ Symbol *Target = File->getSymbol (Rel.SymbolTableIndex );
344
+ if (!Target || isa<DefinedAbsolute>(Target))
332
345
continue ;
333
346
Res->emplace_back (RVA + Rel.VirtualAddress , Ty);
334
347
}
Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ void markLive(const std::vector<Chunk *> &Chunks) {
63
63
64
64
// Mark all symbols listed in the relocation table for this section.
65
65
for (Symbol *B : SC->symbols ())
66
- AddSym (B);
66
+ if (B)
67
+ AddSym (B);
67
68
68
69
// Mark associative sections if any.
69
70
for (SectionChunk *C : SC->children ())
Original file line number Diff line number Diff line change
1
+ # RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
2
+ # RUN: lld-link -entry:__ImageBase -subsystem:console -debug %t.obj
3
+
4
+ .section .debug_info,"dr"
5
+ .quad .Ldrectve
6
+
7
+ .section .drectve
8
+ .Ldrectve:
Original file line number Diff line number Diff line change
1
+ # RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
2
+ # RUN: not lld-link -entry:__ImageBase -subsystem:console %t.obj 2>&1 | FileCheck %s
3
+
4
+ .text
5
+ # CHECK: error: relocation against symbol in discarded section: .drectve
6
+ .quad .Ldrectve
7
+
8
+ .section .drectve
9
+ .Ldrectve:
You can’t perform that action at this time.
0 commit comments