Compilation failing on EnableABIBreakingChecks
Asked Answered
S

5

11

I recently installed LLVM v8.0.0 (on RHEL 7.4). I am going through the LLVM Kaleidoscope tutorial to learn how to use the system, but am running into an issue linking.

Per the tutorial (end of chapter 2), I run:

clang++ -g -O3 kld.cpp `llvm-config --cxxflags` -o kld

It compiles, but the linker fails on:

/tmp/kld-f7264f.o:(.data+0x0): undefined reference to `llvm::EnableABIBreakingChecks'
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)

I suspected this may have been an issue with llvm-config, so I also tried using the --ldflags and --system-libs flags, but no luck.

llvm-config --cxxflags gives (reformatted for readability)

-I~/project/llvm-src/include -I~/project/llvm-build/include 
-fPIC -fvisibility-inlines-hidden
-std=c++11
-Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wno-missing-field-initializers -pedantic -Wno-long-long
-Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment
-g 
-fno-exceptions -fno-rtti
-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

Where ~/... is just the path to my home directory (edited for privacy; the actual output is a fullpath). I am working on a shared system that requires I install new software locally.

The tutorial code never references ABI explicitly, so I assume this must be some kind of compiler-flags issue. greping for the missing symbol in non-binary files gives an extern declaration in include/llvm/Config/abi-breaking.h and the real declaration in lib/Support/Error.cpp:

#if LLVM_ENABLE_ABI_BREAKING_CHECKS
int EnableABIBreakingChecks;
#else
int DisableABIBreakingChecks;
#endif

I thought I would try re-compiling, then, with -DLLVM_ENABLE_ABI_BREAKING_CHECKS. That also does that work.

I'm not really clear what the ABI breaking checks are doing in the first place, and this may be way over my C++ comfort level. But how can I silence this error, if I don't need the referenced functionality; or fix it, if i do?

Thanks.

Scatter answered 16/12, 2018 at 18:1 Comment(0)
S
8

Turns out the answer was hidden in abi-breaking.h:

/* Allow selectively disabling link-time mismatch checking so that header-only
   ADT content from LLVM can be used without linking libSupport. */
#if !LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING

I'm not sure if I'll need libSupport down the line, but compiling with LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1 works for the time being.

Scatter answered 17/12, 2018 at 23:18 Comment(1)
From llvm docs: > LLVM_ABI_BREAKING_CHECKS:STRING Used to decide if LLVM should be built with ABI breaking checks or not. Allowed values are WITH_ASSERTS (default), FORCE_ON and FORCE_OFF ... linkMarquise
W
5

Based on the discussion in llvm irc channel.

Try the following command to compile : clang++ -O3 -c $(llvm-config --cxxflags) source_file.cpp -o obj_code.

Then try linking with this command : clang++ obj_code $(llvm-config --ldflags --libs) -lpthread.

I think linking part doesn't mentioned in the kaleidoscope section. The above solution worked for me.

Wayward answered 31/12, 2018 at 20:2 Comment(0)
T
5

Add linkage with LLVMSupport library will also solve this problem.

With this CMake snippet:

find_package(LLVM REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

add_executable(main main.cpp)
target_link_libraries(main LLVMSupport)
Techy answered 20/8, 2020 at 6:22 Comment(0)
D
2

I don't know the influence and reason why it works. But when I add -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING, the errors disappear.

clang++ xxx -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING

ref: https://www.coder.work/article/6278120
https://blog.csdn.net/qq_37887537/article/details/112790961

Derinna answered 7/1, 2022 at 2:18 Comment(0)
T
0

These answers are all way too complicated. Replace llvm-config --cxxflags with llvm-config --cxxflags --libs and it should run fine (properly, instead of with the out of sight, out of mind mentality that your solution uses).

Turkmen answered 26/4 at 2:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.