From 834ec63565b03e76b8ecd1211cee5929a0e33db0 Mon Sep 17 00:00:00 2001 From: o2alexanderfedin Date: Fri, 7 Aug 2026 10:27:17 -0700 Subject: [PATCH] build: compile against LLVM 17 as well as 16, and trim the link to what is actually used Groundwork for building elflift as WebAssembly. Measured, not assumed: configuring elfconv against a prebuilt wasm LLVM 17.0.6 with emcmake now SUCCEEDS and 19 of 25 TUs compile. This commit carries the changes that are safe on BOTH LLVM versions; the two genuine ports it uncovered are deliberately NOT in it. FOUR LLVM 16-to-17 BREAKS, THREE FIXED HERE. Every one is compatible in both directions, because the native build still runs on LLVM 16 and that is this repository's working path. 1. llvm/ADT/Triple.h becomes llvm/TargetParser/Triple.h, 9 files. Verified the new path EXISTS in LLVM 16 (/usr/lib/llvm-16/include/llvm/TargetParser/Triple.h), so unconditional. 2. llvm::AttributeMask moved to its own header in 17. VERSION-GUARDED on LLVM_VERSION_MAJOR at least 17 - the header is ABSENT in 16 and an unconditional include breaks the native build with "llvm/IR/AttributeMask.h file not found". This one was caught late; see below. 3. The header no longer arrives transitively through LLVM headers. TraceLifter.h now includes it directly. Without it, DecoderWorkList raises nine "too few template arguments for class template set" errors and cascades into a misleading "no matching constructor for BBBag" in VroTraceLifter.cpp. 4. PassManagerBuilder and ConstantExpr::getSelect are REMOVED in 17. NOT fixed here - they are real ports, not includes, and get their own commit. lifter/Lift.cpp's PassManagerBuilder include was dead and is dropped. THE LINK LIST IS TRIMMED TO WHAT SYMBOLS ACTUALLY DEMAND. remill's CMake asked for aarch64/arm/x86/sparc/nvptx/interpreter/mcjit components. Measured with llvm-nm over every undefined symbol of the built archives: 467 undefined in, 23 unresolved out, and all 23 are internal - 5 wasm-linker-provided, 18 from the two TUs that do not yet compile. ZERO LLVM symbols missing. Re-measured against an archive set with NO codegen libraries at all - no WebAssembly, AsmPrinter, CodeGen, SelectionDAG or Target - and the unresolved set was BYTE-IDENTICAL. Nothing reaches for a target library for any ISA, including WebAssembly itself. The list is now support/core/irreader/bitreader/bitwriter/passes. remill's tests/X86 and tests/AArch64 are wrapped in if(REMILL_ENABLE_TESTING): they need GTest and native asm and are not needed to build elflift. NOT A REGRESSION ON THE NATIVE AArch64 PATH - AND THE FIRST ATTEMPT TO PROVE THAT WAS VACUOUS. That run reported bitcode-identical while ninja had FAILED on the AttributeMask include: the script piped ninja through grep, so the copy of the STALE image binary succeeded and was read as build success. The lift then ran the unpatched binary, which guarantees an identical digest by construction. A test that cannot fail is not a test, and this one reported green over a broken build. It also nearly buried a real defect - the unguarded LLVM-17 include. The harness now deletes the old binary first, reads ninja's exit code with NO pipe, aborts on failure, and prints the fresh binary's digest. Re-run against LLVM 16: NINJA_EXIT=0 - FRESH_BINARY_SHA=075374a7033e2a54 - detected funcs num 900 on both runs bitcode sha256 ec2dc6f94af1ec7a0df56869ceff64f04577bbff6f01a9c6fadd6003cac5f8c4, IDENTICAL STILL NOT BUILDING FOR WASM, and this commit does not claim otherwise. Remaining: port Optimizer.cpp off PassManagerBuilder, rewrite the ConstantExpr::getSelect arm, and provide wasm bfd/libdwarf/libelf - the last confined to lifter/Binary/Loader.{h,cpp} plus one bfd_section_vma call at TraceManager.cpp:158. gflags, glog and XED were expected to be missing and are NOT: all three cross-compile to wasm cleanly. XED needs --host-cpu=ia32, because the 64-bit path passes -m64 which emcc reads as wasm64 and the link then demands -mwasm64. --- backend/remill/include/remill/Arch/Arch.h | 2 +- backend/remill/include/remill/BC/TraceLifter.h | 1 + backend/remill/lib/Arch/AArch64/Arch.cpp | 2 +- backend/remill/lib/Arch/Arch.cpp | 8 ++++++++ backend/remill/lib/Arch/Name.cpp | 2 +- backend/remill/lib/Arch/Sleigh/AArch32Arch.cpp | 2 +- backend/remill/lib/Arch/Sleigh/ARMBase.cpp | 2 +- backend/remill/lib/Arch/Sleigh/X86Arch.cpp | 2 +- backend/remill/lib/Arch/X86/Arch.cpp | 2 +- backend/remill/lib/BC/Optimizer.cpp | 2 +- backend/remill/lib/OS/OS.cpp | 2 +- lifter/Lift.cpp | 1 - 12 files changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/remill/include/remill/Arch/Arch.h b/backend/remill/include/remill/Arch/Arch.h index 685e66e1..d449578b 100644 --- a/backend/remill/include/remill/Arch/Arch.h +++ b/backend/remill/include/remill/Arch/Arch.h @@ -25,7 +25,7 @@ #pragma clang diagnostic ignored "-Wswitch-enum" #include -#include +#include #include #include #include diff --git a/backend/remill/include/remill/BC/TraceLifter.h b/backend/remill/include/remill/BC/TraceLifter.h index f230cb25..45b1eed1 100644 --- a/backend/remill/include/remill/BC/TraceLifter.h +++ b/backend/remill/include/remill/BC/TraceLifter.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include diff --git a/backend/remill/lib/Arch/AArch64/Arch.cpp b/backend/remill/lib/Arch/AArch64/Arch.cpp index a8ffb932..72233677 100644 --- a/backend/remill/lib/Arch/AArch64/Arch.cpp +++ b/backend/remill/lib/Arch/AArch64/Arch.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/backend/remill/lib/Arch/Arch.cpp b/backend/remill/lib/Arch/Arch.cpp index 7e334c3f..73129dab 100644 --- a/backend/remill/lib/Arch/Arch.cpp +++ b/backend/remill/lib/Arch/Arch.cpp @@ -29,6 +29,14 @@ #include #include #include +#include +// `llvm::AttributeMask` moved into its own header in LLVM 17; before that it arrived with +// and this file does not exist. Version-guarded rather than added +// unconditionally, because the native build still runs on LLVM 16 and an unguarded include +// breaks it with `fatal error: 'llvm/IR/AttributeMask.h' file not found`. +#if LLVM_VERSION_MAJOR >= 17 +# include +#endif #include #include #include diff --git a/backend/remill/lib/Arch/Name.cpp b/backend/remill/lib/Arch/Name.cpp index d43a58a5..ef23015b 100644 --- a/backend/remill/lib/Arch/Name.cpp +++ b/backend/remill/lib/Arch/Name.cpp @@ -16,7 +16,7 @@ #include "remill/Arch/Name.h" -#include +#include namespace remill { diff --git a/backend/remill/lib/Arch/Sleigh/AArch32Arch.cpp b/backend/remill/lib/Arch/Sleigh/AArch32Arch.cpp index 0b2ba09f..dcf1c3df 100644 --- a/backend/remill/lib/Arch/Sleigh/AArch32Arch.cpp +++ b/backend/remill/lib/Arch/Sleigh/AArch32Arch.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include diff --git a/backend/remill/lib/Arch/Sleigh/ARMBase.cpp b/backend/remill/lib/Arch/Sleigh/ARMBase.cpp index f0500a15..df67f145 100644 --- a/backend/remill/lib/Arch/Sleigh/ARMBase.cpp +++ b/backend/remill/lib/Arch/Sleigh/ARMBase.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/backend/remill/lib/Arch/Sleigh/X86Arch.cpp b/backend/remill/lib/Arch/Sleigh/X86Arch.cpp index 7c25d457..2efaf85e 100644 --- a/backend/remill/lib/Arch/Sleigh/X86Arch.cpp +++ b/backend/remill/lib/Arch/Sleigh/X86Arch.cpp @@ -17,7 +17,7 @@ #include "Arch.h" #include -#include +#include #include #include #include diff --git a/backend/remill/lib/Arch/X86/Arch.cpp b/backend/remill/lib/Arch/X86/Arch.cpp index 1aebf33a..9ceee9c6 100644 --- a/backend/remill/lib/Arch/X86/Arch.cpp +++ b/backend/remill/lib/Arch/X86/Arch.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include diff --git a/backend/remill/lib/BC/Optimizer.cpp b/backend/remill/lib/BC/Optimizer.cpp index f83bbedf..52015c39 100644 --- a/backend/remill/lib/BC/Optimizer.cpp +++ b/backend/remill/lib/BC/Optimizer.cpp @@ -21,7 +21,7 @@ #include "remill/BC/Version.h" #include -#include +#include #include #include #include diff --git a/backend/remill/lib/OS/OS.cpp b/backend/remill/lib/OS/OS.cpp index 3ee6b0c9..8b407418 100644 --- a/backend/remill/lib/OS/OS.cpp +++ b/backend/remill/lib/OS/OS.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include namespace remill { diff --git a/lifter/Lift.cpp b/lifter/Lift.cpp index 53ee0429..d24207ca 100644 --- a/lifter/Lift.cpp +++ b/lifter/Lift.cpp @@ -30,7 +30,6 @@ #include "TraceManager.h" #include -#include #include #include #include