Add support for producing .o files as PIC.

We then can't handle the relocations in those .o files, but it's progress.
This commit is contained in:
Nick Lewycky
2020-05-26 10:41:13 -07:00
parent c2142752f8
commit b81e241cdf
2 changed files with 26 additions and 5 deletions

View File

@@ -37,6 +37,9 @@ pub struct LLVMConfig {
/// The optimization levels when optimizing the IR.
pub opt_level: OptimizationLevel,
/// Whether to emit PIC.
pub is_pic: bool,
features: Features,
target: Target,
}
@@ -72,12 +75,17 @@ impl LLVMConfig {
enable_nan_canonicalization: true,
enable_verifier: false,
opt_level: OptimizationLevel::Aggressive,
is_pic: false,
features,
target,
}
}
fn reloc_mode(&self) -> RelocMode {
RelocMode::Static
if self.is_pic {
RelocMode::PIC
} else {
RelocMode::Static
}
}
fn code_model(&self) -> CodeModel {
@@ -149,22 +157,25 @@ impl LLVMConfig {
}
impl CompilerConfig for LLVMConfig {
/// Gets the WebAssembly features
/// Gets the WebAssembly features.
fn features(&self) -> &Features {
&self.features
}
/// Emit code suitable for dlopen.
fn enable_pic(&mut self) {
unimplemented!("PIC is not yet implemented in LLVM");
// TODO: although we can emit PIC easily enough, the object file parser
// does not yet support all the relocations.
self.is_pic = true;
}
/// Gets the target that we will use for compiling
/// Gets the target that we will use for compiling.
/// the WebAssembly module
fn target(&self) -> &Target {
&self.target
}
/// Transform it into the compiler
/// Transform it into the compiler.
fn compiler(&self) -> Box<dyn Compiler + Send> {
Box::new(LLVMCompiler::new(&self))
}

View File

@@ -152,6 +152,16 @@ where
// TODO: these constants are not per-arch, we'll need to
// make the whole match per-arch.
goblin::elf::reloc::R_X86_64_64 => RelocationKind::Abs8,
goblin::elf::reloc::R_X86_64_GOT64 => {
return Err(CompileError::Codegen(
"unimplemented PIC relocation R_X86_64_GOT64".into(),
));
}
goblin::elf::reloc::R_X86_64_GOTPC64 => {
return Err(CompileError::Codegen(
"unimplemented PIC relocation R_X86_64_GOTPC64".into(),
));
}
_ => {
return Err(CompileError::Codegen(format!(
"unknown ELF relocation {}",