user120969
user120969

Reputation: 81

LLVm clang , Error: Invalid file format (bad magic) with -fprofile-instr-use

Flag "-fprofile-instr-use" generates error given below. This issue occurs even if we build llvm,clang and compiler-rt using cmake or configure. Please let me know your inputs to resolve this issue

error: Could not read profile: Invalid file format (bad magic)

Thanks,

Steps to reproduce this issue:

$ clang -O2 -fprofile-instr-generate hello.c -o c1.out

$ ls -rlt
-rw-r--r-- 1 root root       70 Jul 11 10:10 hello.c
-rwxr-xr-x 1 root root    15793 Jul 11 10:10 c1.out
-rw-r--r-- 1 root root 12203204 Jul 11 10:10 gmon.out

$ ./c1.out
Hello world

$ ls -rlt
-rw-r--r-- 1 root root       70 Jul 11 10:10 hello.c
-rwxr-xr-x 1 root root    15793 Jul 11 10:10 c1.out
-rw-r--r-- 1 root root 12203204 Jul 11 10:10 gmon.out
-rw-r--r-- 1 root root      104 Jul 11 10:10 default.profraw

$ clang -O2 -fprofile-instr-use=default.profraw hello.c -o c2.out
error: Could not read profile: Invalid file format (bad magic)
1 error generated.

Clang version (July 10th-2014 build from stage):
$ clang -v
clang version 3.5.0 (llvm.org/git/clang.git 5f9d646cba20f309bb69c6c358996d71912c54cd) (llvm.org/git/llvm.git dc90a3ab8ffc841a442888940635306de6131d2f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

OS:  Ubuntu 14.04

LLVM configure: ../llvm/configure --enable-profiling --enable-optimized --enable-shared --disable-debug-runtime --enable-targets=x86 

Upvotes: 3

Views: 2286

Answers (1)

Running Male
Running Male

Reputation: 41

It turns out that step 3 outlined here: http://clang.llvm.org/docs/UsersManual.html#profiling-with-instrumentation

is required even if you only have 1 output file you are using. "Combine profiles from multiple runs and convert the “raw” profile format to the input expected by clang" makes it sound like you should only do this if you have multiple profiles, but you need to do it unconditionally.

Upvotes: 4

Related Questions