@@ -1152,35 +1152,38 @@ void Writer::processRelocations(InputChunk *Chunk) {
1152
1152
ObjFile *File = Chunk->File ;
1153
1153
ArrayRef<WasmSignature> Types = File->getWasmObj ()->types ();
1154
1154
for (const WasmRelocation &Reloc : Chunk->getRelocations ()) {
1155
+ if (Reloc.Type == R_WASM_TYPE_INDEX_LEB) {
1156
+ // Mark target type as live
1157
+ File->TypeMap [Reloc.Index ] = registerType (Types[Reloc.Index ]);
1158
+ File->TypeIsUsed [Reloc.Index ] = true ;
1159
+ continue ;
1160
+ }
1161
+
1162
+ // Other relocation types all have a corresponding symbol
1163
+ auto *Sym = File->getSymbols ()[Reloc.Index ];
1155
1164
switch (Reloc.Type ) {
1156
1165
case R_WASM_TABLE_INDEX_I32:
1157
1166
case R_WASM_TABLE_INDEX_SLEB:
1158
1167
case R_WASM_TABLE_INDEX_REL_SLEB: {
1159
- FunctionSymbol *Sym = File-> getFunctionSymbol (Reloc. Index );
1160
- if (Sym ->hasTableIndex () || !Sym ->hasFunctionIndex () || requiresGOTAccess (Sym ))
1168
+ auto *F = cast<FunctionSymbol>(Sym );
1169
+ if (F ->hasTableIndex () || !F ->hasFunctionIndex () || requiresGOTAccess (F ))
1161
1170
break ;
1162
- Sym ->setTableIndex (TableBase + IndirectFunctions.size ());
1163
- IndirectFunctions.emplace_back (Sym );
1171
+ F ->setTableIndex (TableBase + IndirectFunctions.size ());
1172
+ IndirectFunctions.emplace_back (F );
1164
1173
break ;
1165
1174
}
1166
1175
case R_WASM_TYPE_INDEX_LEB:
1167
- // Mark target type as live
1168
- File->TypeMap [Reloc.Index ] = registerType (Types[Reloc.Index ]);
1169
- File->TypeIsUsed [Reloc.Index ] = true ;
1170
1176
break ;
1171
- case R_WASM_GLOBAL_INDEX_LEB: {
1172
- auto * Sym = File->getSymbols ()[Reloc.Index ];
1177
+ case R_WASM_GLOBAL_INDEX_LEB:
1173
1178
if (!isa<GlobalSymbol>(Sym) && !Sym->isInGOT ()) {
1174
1179
Sym->setGOTIndex (NumImportedGlobals++);
1175
1180
GOTSymbols.push_back (Sym);
1176
1181
}
1177
1182
break ;
1178
- }
1179
1183
case R_WASM_MEMORY_ADDR_SLEB:
1180
1184
case R_WASM_MEMORY_ADDR_LEB:
1181
- case R_WASM_MEMORY_ADDR_REL_SLEB: {
1185
+ case R_WASM_MEMORY_ADDR_REL_SLEB:
1182
1186
if (!Config->Relocatable ) {
1183
- auto * Sym = File->getSymbols ()[Reloc.Index ];
1184
1187
if (Sym->isUndefined () && !Sym->isWeak ()) {
1185
1188
error (toString (File) + " : cannot resolve relocation of type " +
1186
1189
relocTypeToString (Reloc.Type ) +
@@ -1189,34 +1192,29 @@ void Writer::processRelocations(InputChunk *Chunk) {
1189
1192
}
1190
1193
break ;
1191
1194
}
1192
- }
1193
1195
1194
1196
if (Config->Pic ) {
1195
1197
switch (Reloc.Type ) {
1196
1198
case R_WASM_TABLE_INDEX_SLEB:
1197
1199
case R_WASM_MEMORY_ADDR_SLEB:
1198
- case R_WASM_MEMORY_ADDR_LEB: {
1200
+ case R_WASM_MEMORY_ADDR_LEB:
1199
1201
// Certain relocation types can't be used when building PIC output, since
1200
1202
// they would require absolute symbol addresses at link time.
1201
- Symbol *Sym = File->getSymbols ()[Reloc.Index ];
1202
1203
error (toString (File) + " : relocation " +
1203
1204
relocTypeToString (Reloc.Type ) + " cannot be used againt symbol " +
1204
1205
toString (*Sym) + " ; recompile with -fPIC" );
1205
1206
break ;
1206
- }
1207
1207
case R_WASM_TABLE_INDEX_I32:
1208
- case R_WASM_MEMORY_ADDR_I32: {
1208
+ case R_WASM_MEMORY_ADDR_I32:
1209
1209
// These relocation types are only present in the data section and
1210
1210
// will be converted into code by `generateRelocationCode`. This code
1211
1211
// requires the symbols to have GOT entires.
1212
- auto * Sym = File->getSymbols ()[Reloc.Index ];
1213
1212
if (requiresGOTAccess (Sym) && !Sym->isInGOT ()) {
1214
1213
Sym->setGOTIndex (NumImportedGlobals++);
1215
1214
GOTSymbols.push_back (Sym);
1216
1215
}
1217
1216
break ;
1218
1217
}
1219
- }
1220
1218
}
1221
1219
}
1222
1220
}
0 commit comments