start running global constructors

This commit is contained in:
Jacob Lifshay 2026-04-01 21:28:11 -07:00
parent 9ed1b679c0
commit f64b5d7120
Signed by: programmerjake
SSH key fingerprint: SHA256:HnFTLGpSm4Q4Fj502oCFisjZSoakwEuTsJJMSke63RQ
5 changed files with 1096 additions and 196 deletions

3
.gitignore vendored
View file

@ -2,5 +2,6 @@
# See Notices.txt for copyright information
/downloads
/qemu-10.2.2*
/libqemu-ppc64-softmmu.*
*.ll
*.bc
/target

View file

@ -5,6 +5,12 @@ name = "compile-qemu-for-decoder"
version = "0.1.0"
edition = "2024"
[features]
verbose-trace = []
[dependencies]
eyre = "0.6.12"
inkwell = { version = "0.8.0", features = ["no-libffi-linking", "llvm20-1", "target-powerpc", "llvm20-1-prefer-dynamic"], default-features = false }
[profile.dev]
opt-level = 1

View file

@ -28,9 +28,23 @@ function build-qemu() (
--enable-tcg-interpreter \
--without-default-features \
--cross-prefix=powerpc64le-linux-gnu-
QEMU_LIBRARIES_WE_USE=(libqemu-ppc64-softmmu.a libqom.a)
make -j"$(nproc)" "${QEMU_LIBRARIES_WE_USE[@]}"
llvm-link-20 -o ../libqemu-ppc64-softmmu.bc "${QEMU_LIBRARIES_WE_USE[@]}"
target="$(ninja -t query qemu-system-ppc64)"
mapfile -t target_lines <<<"$target"
# add missed libs
link_inputs=(libpage-vary-common.a libqemuutil.a)
# add the rest of the libs and object files
for l in "${target_lines[@]}"; do
if [[ "$l" =~ ^' '([a-z].*)$ ]]; then
link_inputs+=("${BASH_REMATCH[1]}")
elif [[ "$l" == " outputs:" ]]; then
break
fi
done
make -j"$(nproc)" qemu-system-ppc64
echo "linking bitcode"
llvm-link-20 --only-needed --ignore-non-bitcode -o ../qemu-system-ppc64.bc "${link_inputs[@]}"
echo "disassembling bitcode"
llvm-dis-20 -o ../qemu-system-ppc64.ll ../qemu-system-ppc64.bc
)
mkdir -p downloads
@ -43,4 +57,3 @@ download_if_needed "downloads/$QEMU_SOURCE.tar.xz" "$QEMU_SOURCE_HASH" \
"https://download.qemu.org/$QEMU_SOURCE.tar.xz"
build-qemu
llvm-dis-20 -o libqemu-ppc64-softmmu.ll libqemu-ppc64-softmmu.bc

1258
src/lib.rs

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// See Notices.txt for copyright information
use compile_qemu_for_decoder::parse_qemu_ppc64_softmmu;
use compile_qemu_for_decoder::parse_qemu_system_ppc64;
use inkwell::targets::{InitializationConfig, Target};
fn main() -> eyre::Result<()> {
Target::initialize_power_pc(&InitializationConfig::default());
parse_qemu_ppc64_softmmu("libqemu-ppc64-softmmu.bc", 10, 10)
parse_qemu_system_ppc64("qemu-system-ppc64.bc", 10, 10)
}