Hello,
A strange problem appears when upgrading from release_34 to testing. Some transformations to bitcode files cause registered global_ctors to not be called. Here’s an example (I’ve also attached the complete example and pasted it below):
This works:
clang -fsanitize=address -flto -c -o sum.o sum.c
clang -fsanitize=address -o sum sum.o
This doesn’t work:
clang -fsanitize=address -flto -c -o sum.o sum.c
llvm-dis sum.o
llvm-as sum.o.ll -o sum.o
clang -fsanitize=address -o sum sum.o
The second version segfaults when accessing shadow memory, because the memory has not been initialized, because _asan_init* was never called. This is surprising, because in the llvm-disassembly the global constructor still shows up.
The llvm-dis/llvm-as operation should be a no-op, yet the global_ctors get lost in the process. This happens also with other operations that affect global_ctors, e.g., with “opt -insert-gcov-profiling”.
The problem does not occur in the release_34 branch, but I have seen it on both testing and master.
Any idea where this could come from would be much appreciated!
Jonas
testcase:
cat >sum.c <<EOF
#include <stdio.h>
#include <assert.h>
int main() {
const int MAX_SIZE = 100;
int a[MAX_SIZE];
for (int i = 0; i < MAX_SIZE; ++i) {
a[i] = i * i + 4;
}
int n_numbers;
printf(“How many numbers should I sum up? “);
scanf(”%d”, &n_numbers);
int sum = 0;
for (int i = 0; i < n_numbers; ++i) {
sum += a[i];
}
assert(sum >= 0);
printf(“The sum is: %d\n”, sum);
return 0;
}
EOF
set -ex
rm -f *.o *.ll sum
clang -fsanitize=address -flto -c -o sum.o sum.c
llvm-dis sum.o
llvm-as sum.o.ll -o sum.o
clang -fsanitize=address -o sum sum.o
echo 22 | ./sum
test_ctors.sh (638 Bytes)