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

bitcode #5

Open
alexcohn opened this issue Dec 19, 2021 · 0 comments
Open

bitcode #5

alexcohn opened this issue Dec 19, 2021 · 0 comments

Comments

@alexcohn
Copy link

alexcohn commented Dec 19, 2021

Apple requires bitcode for tvOS builds, and strongly encourages bitcode for iOS builds. Also, the compiler has recently added a check in clang/lib/Driver/ToolChains/Clang.cpp, which does not allow -mllvm in CFLAGS when -fembed-bitcode is present.

This didn't happen before, on llvm-9.0.1 (but that was not compatible with the modern Xcode).

I tried to simply remove the error check for mllvm from Clang.cpp, but this resulted in lots of suspicious warnings while compiling and my iOS code, I tried to simply hardcode -mllvm -bcf -mllvm -sub -mllvm -fla -mllvm -sobf in the compiler. Now, build passes smoothly.

Is there a better way to work around this problem? Also, I am not sure (have not tried) that the bitcode that is produced after my 'fix' is valid.

hudjefa pushed a commit to hudjefa/obfuscator-llvm that referenced this issue Feb 14, 2022
Andrei Matei reported a llvm11 core dump for his bpf program
   https://bugs.llvm.org/show_bug.cgi?id=48578
The core dump happens in LiveVariables analysis phase.
  heroims#4 0x00007fce54356bb0 __restore_rt
  heroims#5 0x00007fce4d51785e llvm::LiveVariables::HandleVirtRegUse(unsigned int,
      llvm::MachineBasicBlock*, llvm::MachineInstr&)
  heroims#6 0x00007fce4d519abe llvm::LiveVariables::runOnInstr(llvm::MachineInstr&,
      llvm::SmallVectorImpl<unsigned int>&)
  heroims#7 0x00007fce4d519ec6 llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int)
  heroims#8 0x00007fce4d51a4bf llvm::LiveVariables::runOnMachineFunction(llvm::MachineFunction&)
The bug can be reproduced with llvm12 and latest trunk as well.

Futher analysis shows that there is a bug in BPF peephole
TRUNC elimination optimization, which tries to remove
unnecessary TRUNC operations (a <<= 32; a >>= 32).
Specifically, the compiler did wrong transformation for the
following patterns:
   %1 = LDW ...
   %2 = SLL_ri %1, 32
   %3 = SRL_ri %2, 32
   ... %3 ...
   %4 = SRA_ri %2, 32
   ... %4 ...

The current transformation did not check how many uses of %2
and did transformation like
   %1 = LDW ...
   ... %1 ...
   %4 = SRL_ri %2, 32
   ... %4 ...
and pseudo register %2 is used by not defined and
caused LiveVariables analysis core dump.

To fix the issue, when traversing back from SRL_ri to SLL_ri,
check to ensure SLL_ri has only one use. Otherwise, don't
do transformation.

Differential Revision: https://reviews.llvm.org/D97792

(cherry picked from commit 51cdb780db3b9b46c783efcec672c4da272e9992)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant