iovisor / iovisor/bcc

LLVM_DEFINITIONS args broken if arg contains "="

Open
#3,040 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

I wasn't able to build bcc because the LLVM_DEFINITIONS from my llvm build was parsed incorrectly, resulting in invalid compiler flags.

The LLVM_DEFINITIONS that caused the problem for me was
`-D_GLIBCXX_USE_CXX11_ABI=0 -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
`

The resulting compiler flags were
`-D_GLIBCXX_USE_CXX11_ABI=0 -D_GLIBCXX_USE_CXX11_ABI="0 -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"`

Note the quote`"` after `-D_GLIBCXX_USE_CXX11_ABI=` . It looks like cmake is misparsing _GLIBCXX_USE_CXX11_ABI and setting all the args following as it's value, rather than as separate args.

I have a fix but I don't have permission to push up a branch so I couldn't figure out how to create a pull request. Here's the diff:
```
diff --git a/src/cc/CMakeLists.txt b/src/cc/CMakeLists.txt
index 0f02ad6..67c1d49 100644
--- a/src/cc/CMakeLists.txt
+++ b/src/cc/CMakeLists.txt
@@ -12,7 +12,12 @@ include_directories(${LIBELF_INCLUDE_DIRS})
# todo: if check for kernel version
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include/uapi)
-add_definitions(${LLVM_DEFINITIONS})
+
+# add_definitions has a problem parsing "-D_GLIBCXX_USE_CXX11_ABI=0", this is safer
+string(REPLACE "-D" "" LLVM_DEFINITIONS ${LLVM_DEFINITIONS})
+separate_arguments(LLVM_DEFINITIONS)
+add_compile_definitions(${LLVM_DEFINITIONS})
+
configure_file(libbcc.pc.in libbcc.pc @ONLY)
configure_file(bcc_version.h.in bcc_version.h @ONLY)

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/cc/CMakeLists.txt, where LLVM_DEFINITIONS is passed to add_definitions. Reproduce the bcc build with a definition containing '=' and inspect the generated compiler flags. Done means each LLVM definition remains a separate flag without an incorrectly inserted quote or merged value.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.