@@ -239,6 +239,47 @@ static CodeGenOpt::Level fromRust(LLVMRustCodeGenOptLevel Level) {
239239 }
240240}
241241
242+ enum class LLVMRustRelocMode {
243+ Default,
244+ Static,
245+ PIC,
246+ DynamicNoPic,
247+ ROPI,
248+ RWPI,
249+ ROPIRWPI,
250+ };
251+
252+ #if LLVM_VERSION_LE(3, 8)
253+ static Reloc::Model fromRust (LLVMRustRelocMode RustReloc) {
254+ #else
255+ static Optional<Reloc::Model> fromRust (LLVMRustRelocMode RustReloc) {
256+ #endif
257+ switch (RustReloc) {
258+ case LLVMRustRelocMode::Default:
259+ #if LLVM_VERSION_LE(3, 8)
260+ return Reloc::Default;
261+ #else
262+ return None;
263+ #endif
264+ case LLVMRustRelocMode::Static:
265+ return Reloc::Static;
266+ case LLVMRustRelocMode::PIC:
267+ return Reloc::PIC_;
268+ case LLVMRustRelocMode::DynamicNoPic:
269+ return Reloc::DynamicNoPIC;
270+ #if LLVM_VERSION_GE(4, 0)
271+ case LLVMRustRelocMode::ROPI:
272+ return Reloc::ROPI;
273+ case LLVMRustRelocMode::RWPI:
274+ return Reloc::RWPI;
275+ case LLVMRustRelocMode::ROPIRWPI:
276+ return Reloc::ROPI_RWPI;
277+ #endif
278+ default :
279+ llvm_unreachable (" Bad RelocModel." );
280+ }
281+ }
282+
242283#if LLVM_RUSTLLVM
243284// / getLongestEntryLength - Return the length of the longest entry in the table.
244285// /
@@ -290,46 +331,14 @@ extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
290331
291332extern " C" LLVMTargetMachineRef LLVMRustCreateTargetMachine (
292333 const char *TripleStr, const char *CPU, const char *Feature,
293- LLVMRustCodeModel RustCM, int Reloc ,
334+ LLVMRustCodeModel RustCM, LLVMRustRelocMode RustReloc ,
294335 LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
295336 bool PositionIndependentExecutable, bool FunctionSections,
296337 bool DataSections) {
297338
298- #if LLVM_VERSION_LE(3, 8)
299- Reloc::Model RM;
300- #else
301- Optional<Reloc::Model> RM;
302- #endif
303339 auto CM = fromRust (RustCM);
304340 auto OptLevel = fromRust (RustOptLevel);
305-
306- switch (Reloc) {
307- case 1 :
308- RM = Reloc::Static;
309- break ;
310- case 2 :
311- RM = Reloc::PIC_;
312- break ;
313- case 3 :
314- RM = Reloc::DynamicNoPIC;
315- break ;
316- #if LLVM_VERSION_GE(4, 0)
317- case 4 :
318- RM = Reloc::ROPI;
319- break ;
320- case 5 :
321- RM = Reloc::RWPI;
322- break ;
323- case 6 :
324- RM = Reloc::ROPI_RWPI;
325- break ;
326- #endif
327- default :
328- #if LLVM_VERSION_LE(3, 8)
329- RM = Reloc::Default;
330- #endif
331- break ;
332- }
341+ auto RM = fromRust (RustReloc);
333342
334343 std::string Error;
335344 Triple Trip (Triple::normalize (TripleStr));
0 commit comments