[LLVMdev] Global constructors "get lost" when transforming bitcode files
Rafael EspĂndola
rafael.espindola at gmail.com
Fri Jul 4 14:04:19 PDT 2014
Are you setting DYLD_LIBRARY_PATH when running on OS X? The linker on
OS X uses that to findl ibLTO.dylib.
At least for me setting DYLD_LIBRARY_PATH when running clang in the
linking stage fixes the problem.
I would still be curious to know how the old (system) libLTO.dylib can
read the bitcode output by clang but not llvm-as.
On 3 July 2014 13:06, Jonas Wagner <jonas.wagner at epfl.ch> wrote:
> 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
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
More information about the llvm-dev
mailing list