<div dir="ltr">Hello,<div><br></div><div>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):</div>

<div><br></div><div>This works:</div><div><br></div><div>    clang -fsanitize=address  -flto -c -o sum.o sum.c</div><div>    clang -fsanitize=address -o sum sum.o<br></div><div><br></div><div>This doesn't work:</div>
<div>
<br></div><div>    clang -fsanitize=address  -flto -c -o sum.o sum.c</div><div>    llvm-dis sum.o</div><div>    llvm-as sum.o.ll -o sum.o</div><div>    clang -fsanitize=address -o sum sum.o</div><div><br></div><div>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.</div>

<div><br></div><div>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".</div>

<div><br></div><div>The problem does not occur in the release_34 branch, but I have seen it on both testing and master.</div><div><br></div><div>Any idea where this could come from would be much appreciated!</div><div>Jonas</div>

<div><br></div><div><br></div><div>testcase:</div><div><br></div><div><div>cat >sum.c <<EOF</div><div>#include <stdio.h></div><div>#include <assert.h></div><div><br></div><div>int main() {</div><div>
    const int MAX_SIZE = 100;</div>
<div>    int a[MAX_SIZE];</div><div><br></div><div>    for (int i = 0; i < MAX_SIZE; ++i) {</div><div>        a[i] = i * i + 4;</div><div>    }</div><div><br></div><div>    int n_numbers;</div><div>    printf("How many numbers should I sum up? ");</div>

<div>    scanf("%d", &n_numbers);</div><div><br></div><div>    int sum = 0;</div><div>    for (int i = 0; i < n_numbers; ++i) {</div><div>        sum += a[i];</div><div>    }</div><div><br></div><div>    assert(sum >= 0);</div>

<div>    printf("The sum is: %d\n", sum);</div><div>    return 0;</div><div>}</div><div>EOF</div><div><br></div><div>set -ex</div><div>rm -f *.o *.ll sum</div><div><br></div><div>clang -fsanitize=address  -flto -c -o sum.o sum.c</div>

<div><br></div><div>llvm-dis sum.o</div><div>llvm-as sum.o.ll -o sum.o</div><div><br></div><div>clang -fsanitize=address -o sum sum.o</div><div><br></div><div>echo 22 | ./sum</div></div><div><br></div></div>