travitch / build-bom

Dynamically discover the commands used to create a piece of software
Apache License 2.0
45 stars 8 forks source link

Generating bitcode fails when compiling directly to an executable #34

Closed langston-barrett closed 2 years ago

langston-barrett commented 2 years ago
$ cat Makefile
CC := clang
CFLAGS :=  -Wall -Werror -g

hello-world: hello-world.c
    $(CC) $(CFLAGS) -o "$@" "$<"

.DEFAULT: build
.PHONY: build
build: hello-world

.PHONY: clean
clean:
    rm -f hello-world

$ cat hello-world.c
#include <stdio.h>

int main() {
  printf("Hello, world!\n");
}

$ make clean && env NIX_CC_USE_RESPONSE_FILE=-1 build-bom generate-bitcode --verbose -- make

rm -f hello-world
clang -Wall -Werror -g -o "hello-world" "hello-world.c"
Bitcode Generation Summary
 0 build steps skipped due to having a pipe as an input or output
 0 build steps skipped due to using a response file (@file)
 0 unresolved outputs with multiple inputs
 0 original build commands failed, causing us to skip bitcode generation
 0 inputs skipped due to being only assembled (-S)
 0 bitcode compilation errors
 0 errors attaching bitcode to object files
 0 attempts at generating bitcode
 0 successful bitcode captures
 last bitcode capture: "<none>"

$ ./hello-world
Hello, world!

$ build-bom extract-bitcode --output=hello-world.bc hello-world

objcopy: hello-world: can't dump section '.llvm_bitcode' - it does not exist: bad value
tar: /run/user/1000/.tmpRs1m09/bitcode.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
llvm-link: Not enough positional command line arguments specified!
Must specify at least 1 positional argument: See: llvm-link -help