Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit position dependent code for embedded targets #15174

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/compiler/crystal/codegen/target.cr
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ class Crystal::Codegen::Target
@architecture == "avr"
end

def embedded?
environment_parts.any? { |part| part == "eabi" || part == "eabihf" }
end

def to_target_machine(cpu = "", features = "", optimization_mode = Compiler::OptimizationMode::O0,
code_model = LLVM::CodeModel::Default) : LLVM::TargetMachine
case @architecture
Expand Down Expand Up @@ -228,8 +232,14 @@ class Crystal::Codegen::Target
in .o0? then LLVM::CodeGenOptLevel::None
end

if embedded?
reloc = LLVM::RelocMode::Static
else
reloc = LLVM::RelocMode::PIC
end

target = LLVM::Target.from_triple(self.to_s)
machine = target.create_target_machine(self.to_s, cpu: cpu, features: features, opt_level: opt_level, code_model: code_model).not_nil!
machine = target.create_target_machine(self.to_s, cpu: cpu, features: features, opt_level: opt_level, reloc: reloc, code_model: code_model).not_nil!
# FIXME: We need to disable global isel until https://reviews.llvm.org/D80898 is released,
# or we fixed generating values for 0 sized types.
# When removing this, also remove it from the ABI specs and jit compiler.
Expand Down
Loading