Skip to content

Commit b592f29

Browse files
committed
Treat extern in compiler-builtins as used
We have to preserve the symbols of the built-in functions during LTO.
1 parent 665da1e commit b592f29

File tree

2 files changed

+8
-106
lines changed

2 files changed

+8
-106
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
5454
// export level, however, as they're just implementation details.
5555
// Down below we'll hardwire all of the symbols to the `Rust` export
5656
// level instead.
57-
let special_runtime_crate =
58-
tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
57+
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
58+
let special_runtime_crate = tcx.is_panic_runtime(LOCAL_CRATE) || is_compiler_builtins;
5959

6060
let mut reachable_non_generics: DefIdMap<_> = tcx
6161
.reachable_set(())
@@ -107,7 +107,11 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
107107
.map(|def_id| {
108108
// We won't link right if this symbol is stripped during LTO.
109109
let name = tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())).name;
110-
let used = name == "rust_eh_personality";
110+
// We have to preserve the symbols of the built-in functions during LTO.
111+
let is_builtin_fn = is_compiler_builtins
112+
&& symbol_export_level(tcx, def_id.to_def_id())
113+
.is_below_threshold(SymbolExportLevel::C);
114+
let used = is_builtin_fn || name == "rust_eh_personality";
111115

112116
let export_level = if special_runtime_crate {
113117
SymbolExportLevel::Rust

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+1-103
Original file line numberDiff line numberDiff line change
@@ -1120,102 +1120,6 @@ extern "C" void LLVMRustPrintPasses() {
11201120
PB.printPassNames(outs());
11211121
}
11221122

1123-
// from https://github.com/llvm/llvm-project/blob/7021182d6b43de9488ab70de626192ce70b3a4a6/llvm/lib/Object/IRSymtab.cpp#L48-L57
1124-
static const char *PreservedLibcallSymbols[] = {
1125-
#define HANDLE_LIBCALL(code, name) name,
1126-
#include "llvm/IR/RuntimeLibcalls.def"
1127-
#undef HANDLE_LIBCALL
1128-
// RuntimeLibcalls.def missing symbols.
1129-
"__ctzsi2",
1130-
"__ctzdi2",
1131-
"__ctzti2",
1132-
"__ffssi2",
1133-
"__ffsdi2",
1134-
"__ffsti2",
1135-
"__paritysi2",
1136-
"__paritydi2",
1137-
"__parityti2",
1138-
"__popcountsi2",
1139-
"__popcountdi2",
1140-
"__popcountti2",
1141-
"__bswapsi2",
1142-
"__bswapdi2",
1143-
"__negti2",
1144-
"__udivmoddi4",
1145-
"__udivmodti4",
1146-
"__udivmodsi4",
1147-
"__divmodsi4",
1148-
"__divmoddi4",
1149-
"__divmodti4",
1150-
"__absvsi2",
1151-
"__absvdi2",
1152-
"__absvti2",
1153-
"__negvsi2",
1154-
"__negvdi2",
1155-
"__negvti2",
1156-
"__addvsi3",
1157-
"__addvdi3",
1158-
"__addvti3",
1159-
"__subvsi3",
1160-
"__subvdi3",
1161-
"__subvti3",
1162-
"__mulvsi3",
1163-
"__mulvdi3",
1164-
"__mulvti3",
1165-
"__cmpdi2",
1166-
"__cmpti2",
1167-
"__ucmpdi2",
1168-
"__ucmpti2",
1169-
"__mulsc3",
1170-
"__muldc3",
1171-
"__mulxc3",
1172-
"__multc3",
1173-
"__divsc3",
1174-
"__divdc3",
1175-
"__divxc3",
1176-
"__divtc3",
1177-
"__clear_cache",
1178-
"__enable_execute_stack",
1179-
"__gcc_personality_v0",
1180-
"__eprintf",
1181-
"__emutls_get_address",
1182-
"__trampoline_setup",
1183-
"__addsf3vfp",
1184-
"__adddf3vfp",
1185-
"__divsf3vfp",
1186-
"__divdf3vfp",
1187-
"__eqsf2vfp",
1188-
"__eqdf2vfp",
1189-
"__extendsfdf2vfp",
1190-
"__fixdfsivfp",
1191-
"__fixsfsivfp",
1192-
"__fixunssfsivfp",
1193-
"__fixunsdfsivfp",
1194-
"__floatsidfvfp",
1195-
"__floatsisfvfp",
1196-
"__floatunssidfvfp",
1197-
"__floatunssisfvfp",
1198-
"__gedf2vfp",
1199-
"__gesf2vfp",
1200-
"__gtdf2vfp",
1201-
"__gtsf2vfp",
1202-
"__ledf2vfp",
1203-
"__lesf2vfp",
1204-
"__ltdf2vfp",
1205-
"__ltsf2vfp",
1206-
"__muldf3vfp",
1207-
"__mulsf3vfp",
1208-
"__nedf2vfp",
1209-
"__negdf2vfp",
1210-
"__negsf2vfp",
1211-
"__negsf2vfp",
1212-
"__subdf3vfp",
1213-
"__subsf3vfp",
1214-
"__truncdfsf2vfp",
1215-
"__unorddf2vfp",
1216-
"__unordsf2vfp",
1217-
};
1218-
12191123
extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
12201124
size_t Len) {
12211125
auto PreserveFunctions = [=](const GlobalValue &GV) {
@@ -1231,7 +1135,7 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
12311135
return true;
12321136
}
12331137
}
1234-
return llvm::is_contained(PreservedLibcallSymbols, GV.getName());
1138+
return false;
12351139
};
12361140

12371141
internalizeModule(*unwrap(M), PreserveFunctions);
@@ -1389,12 +1293,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
13891293
auto GUID = GlobalValue::getGUID(preserved_symbols[i]);
13901294
Ret->GUIDPreservedSymbols.insert(GUID);
13911295
}
1392-
for (int i = 0; i < sizeof(PreservedLibcallSymbols) / sizeof(PreservedLibcallSymbols[0]); i++) {
1393-
if (auto *PreservedLibcallSymbol = PreservedLibcallSymbols[i]) {
1394-
auto GUID = GlobalValue::getGUID(PreservedLibcallSymbol);
1395-
Ret->GUIDPreservedSymbols.insert(GUID);
1396-
}
1397-
}
13981296

13991297
// Collect the import/export lists for all modules from the call-graph in the
14001298
// combined index

0 commit comments

Comments
 (0)