localacct
localacct

Reputation: 787

Clang errors about instructions when rebuilding human readable .ll files

I converted some binary bitcode files into human readable form using llvm-dis. When I tried to rebuild those .ll files into the main binary, I will see errors such as

clang -cc1 version 13.0.0 (clang-1300.0.29.30) default target x86_64-apple-darwin20.6.0
arm64_6B51A8D2-17A7-4252-8C72-2D1877B77E09.ll:240:175: error: expected metadata after comma
  %24 = atomicrmw add i64* bitcast (i8* getelementptr inbounds (%"__ir_hidden#224_", %"__ir_hidden#224_"* @"\01__hidden#199_", i64 0, i32 0, i64 24) to i64*), i64 1 acquire, align 8, !dbg !139, !noalias !150

It seems that clang encountered a problem trying to parse the instructions translated by llvm-dis?

EDIT 9 Feb 2022

I did not make any changes to the .ll files. This was what I did

#!/bin/bash

for bitcodefile in $(ls | grep -i ^arm64)
do
    echo $bitcodefile
    llvm-dis $bitcodefile -o ./readable2/$bitcodefile.ll
done

Then I tried to rebuild the .ll files into the final binary

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch arm64 -mios-version-min=12.2.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.2.sdk -dead_strip -v -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/ -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/ -fembed-bitcode *.ll -o 64bit_executable -F /path/to/Frameworks

Upvotes: 2

Views: 150

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

It seems you are using Apple-provided clang to compile LLVM IR produced by mainline LLVM. This in general might not work, you need to use "matching" IR producers / consumers (e.g. mainline clang of the same version).

Upvotes: 1

Related Questions