@@ -1351,19 +1351,47 @@ static void addSymbolToRVASet(SymbolRVASet &RVASet, Defined *S) {
1351
1351
// symbol in an executable section.
1352
1352
static void maybeAddAddressTakenFunction (SymbolRVASet &AddressTakenSyms,
1353
1353
Symbol *S) {
1354
- auto *D = dyn_cast_or_null<DefinedCOFF>(S);
1355
-
1356
- // Ignore undefined symbols and references to non-functions (e.g. globals and
1357
- // labels).
1358
- if (!D ||
1359
- D->getCOFFSymbol ().getComplexType () != COFF::IMAGE_SYM_DTYPE_FUNCTION)
1354
+ if (!S)
1360
1355
return ;
1361
1356
1362
- // Mark the symbol as address taken if it's in an executable section.
1363
- Chunk *RefChunk = D->getChunk ();
1364
- OutputSection *OS = RefChunk ? RefChunk->getOutputSection () : nullptr ;
1365
- if (OS && OS->Header .Characteristics & IMAGE_SCN_MEM_EXECUTE)
1366
- addSymbolToRVASet (AddressTakenSyms, D);
1357
+ switch (S->kind ()) {
1358
+ case Symbol::DefinedLocalImportKind:
1359
+ case Symbol::DefinedImportDataKind:
1360
+ // Defines an __imp_ pointer, so it is data, so it is ignored.
1361
+ break ;
1362
+ case Symbol::DefinedCommonKind:
1363
+ // Common is always data, so it is ignored.
1364
+ break ;
1365
+ case Symbol::DefinedAbsoluteKind:
1366
+ case Symbol::DefinedSyntheticKind:
1367
+ // Absolute is never code, synthetic generally isn't and usually isn't
1368
+ // determinable.
1369
+ break ;
1370
+ case Symbol::LazyKind:
1371
+ case Symbol::UndefinedKind:
1372
+ // Undefined symbols resolve to zero, so they don't have an RVA. Lazy
1373
+ // symbols shouldn't have relocations.
1374
+ break ;
1375
+
1376
+ case Symbol::DefinedImportThunkKind:
1377
+ // Thunks are always code, include them.
1378
+ addSymbolToRVASet (AddressTakenSyms, cast<Defined>(S));
1379
+ break ;
1380
+
1381
+ case Symbol::DefinedRegularKind: {
1382
+ // This is a regular, defined, symbol from a COFF file. Mark the symbol as
1383
+ // address taken if the symbol type is function and it's in an executable
1384
+ // section.
1385
+ auto *D = cast<DefinedRegular>(S);
1386
+ if (D->getCOFFSymbol ().getComplexType () == COFF::IMAGE_SYM_DTYPE_FUNCTION) {
1387
+ Chunk *RefChunk = D->getChunk ();
1388
+ OutputSection *OS = RefChunk ? RefChunk->getOutputSection () : nullptr ;
1389
+ if (OS && OS->Header .Characteristics & IMAGE_SCN_MEM_EXECUTE)
1390
+ addSymbolToRVASet (AddressTakenSyms, D);
1391
+ }
1392
+ break ;
1393
+ }
1394
+ }
1367
1395
}
1368
1396
1369
1397
// Visit all relocations from all section contributions of this object file and
0 commit comments