Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
os: [ubuntu-24.04, windows-2022]
configuration: [Debug, Release]
runs-on: ${{ matrix.os }}
timeout-minutes: 45
timeout-minutes: 60

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Test (Ubuntu)
id: test_linux
if: runner.os == 'Linux'
timeout-minutes: 20
timeout-minutes: 35
shell: bash
run: |
set -o pipefail
Expand Down Expand Up @@ -171,6 +171,10 @@ jobs:
llvm-config-${ABSOLUTE_LLVM_VERSION} --version
ninja --version || true
node --version || true
# The backend selects a target CPU from the host model, so a runner whose
# advertised model implies features the VM masks off is worth spotting in
# the log rather than inferring from a SIGILL.
lscpu || true
} > ci-logs/toolchain.txt 2>&1

- name: Record toolchain versions (Windows)
Expand Down
2 changes: 2 additions & 0 deletions Absolute-CodeGen/include/codegen_pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
#include <llvm/TargetParser/Triple.h>
#if LLVM_VERSION_MAJOR >= 18
#include <llvm/TargetParser/Host.h>
#include <llvm/TargetParser/SubtargetFeature.h>
#else
#include <llvm/Support/Host.h>
#include <llvm/MC/SubtargetFeature.h>
#endif

#include <algorithm>
Expand Down
23 changes: 22 additions & 1 deletion Absolute-CodeGen/src/codegen_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,19 +1263,40 @@ namespace Absolute {

llvm::TargetOptions options;
std::string cpu = "generic";
std::string features;
llvm::Reloc::Model reloc = llvm::Reloc::PIC_;
if (IsWebAssemblyTriple(triple)) {
// Wasm objects use a generic CPU; PIC is the usual reloc model.
cpu = "generic";
reloc = llvm::Reloc::PIC_;
}
else {
// The host CPU name only identifies a microarchitecture, it does not say
// which of that microarchitecture's features the machine actually exposes.
// A virtualised host can report a model whose default feature set includes
// instructions the hypervisor masks off, and selecting by name alone then
// emits code the CPU refuses to execute. Pin the feature string to what the
// host really advertises so generated objects stay runnable on that host.
const std::string hostCpu = llvm::sys::getHostCPUName().str();
if (!hostCpu.empty()) cpu = hostCpu;

#if LLVM_VERSION_MAJOR >= 19
const llvm::StringMap<bool> hostFeatures = llvm::sys::getHostCPUFeatures();
const bool detectedFeatures = !hostFeatures.empty();
#else
llvm::StringMap<bool> hostFeatures;
const bool detectedFeatures = llvm::sys::getHostCPUFeatures(hostFeatures);
#endif
if (detectedFeatures) {
llvm::SubtargetFeatures hostSubtarget;
for (const llvm::StringMapEntry<bool>& feature : hostFeatures)
hostSubtarget.AddFeature(feature.getKey(), feature.getValue());
features = hostSubtarget.getString();
}
}

std::unique_ptr<llvm::TargetMachine> targetMachine(target->createTargetMachine(
tripleName, cpu, "", options, reloc,
tripleName, cpu, features, options, reloc,
std::nullopt,
LlvmCodeGenOptimizationLevel(optimizationLevel)));
if (!targetMachine) Fail("cannot create target machine for '" + tripleName + "'");
Expand Down
Loading