Clang Linking error: undefined reference to function calls added by LLVM pass

Clang Linking error: undefined reference to function calls added by LLVM pass

所以我正在学习本教程 https://www.cs.cornell.edu/~asampson/blog/llvm.html to make a pass that instruments a program by adding calls to an external function (which is logop in rtlib.c). But unlike the tutorial I am trying to instrument a larger code-base which is masstree: https://github.com/kohler/masstree-beta

所以按照 masstree 的指示,我先 运行 ./configure,然后我编辑生成的 Makefile 以使用 clang(而不是 gcc/g++)和 运行 我的通行证。我还在 masstree 源文件中添加 rtlib.c,以便它与其余的 masstree 源文件一起转换为 rtlib.o。这是修改后的 Makefile 的相关部分,我的更改用箭头突出显示(我还将 $(rtlib) 添加到 link 它与其他 .o 文件一起生成可执行文件):

AR = ar
rtlib = rtlib.o  <===
CC2 = clang -w -v -Xclang -load -Xclang  /.../llvm-3.4/Release+Asserts/lib/SkeletonPass.so `llvm-config --cflags` 
CXX2 = clang++ -v -w -Xclang -load -Xclang /.../llvm-3.4/Release+Asserts/lib/SkeletonPass.so -std=c++11 `llvm-config --cppflags --libs --cflags --cxxflags core --ldflags` <===
CC = clang -v <===
CXX = clang++ -v -std=c++11 <===
CPPFLAGS = 
CXXFLAGS = -g -W -Wall -O3
DEPSDIR := .deps
DEPCFLAGS = -MD -MF $(DEPSDIR)/$*.d -MP
ifeq ($(strip $(MEMMGR)), )
  MEMMGR = 
endif
ifneq ($(strip $(KEYSWAP)), )
  CPPFLAGS += -DKEYSWAP
endif
ifneq ($(strip $(NOPREFETCH)), )
  CPPFLAGS += -DNOPREFETCH
endif
ifneq ($(strip $(NOSUPERPAGE)), )
  CPPFLAGS += -DNOSUPERPAGE
endif
LIBS =  -lpthread -lm
LDFLAGS = 

all: test_atomics mtd mtclient mttest

%.o: %.c config.h $(DEPSDIR)/stamp
    $(CXX2) $(CPPFLAGS) $(CXXFLAGS) $(DEPCFLAGS) -include config.h -c -o $@ $<

%.o: %.cc config.h $(DEPSDIR)/stamp
    $(CXX2) $(CPPFLAGS) $(CXXFLAGS) $(DEPCFLAGS) -include config.h -c -o $@ $<

%.S: %.o
    objdump -S $< > $@

libjson.a: json.o string.o straccum.o str.o msgpack.o \
    clp.o kvrandom.o compiler.o memdebug.o kvthread.o
    @/bin/rm -f $@
    $(AR) cru $@ $^

KVTREES = query_masstree.o \
    value_string.o value_array.o value_versioned_array.o \
    string_slice.o

mtd: mtd.o log.o checkpoint.o file.o misc.o $(rtlib) $(KVTREES) \
    kvio.o libjson.a
    $(CXX) $(CXXFLAGS) -o $@ $^ $(MEMMGR) $(LDFLAGS) $(LIBS)

mtclient: mtclient.o misc.o testrunner.o kvio.o $(rtlib) libjson.a
    $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)

mttest: mttest.o misc.o checkpoint.o $(rtlib) $(KVTREES) testrunner.o \
    kvio.o libjson.a
    $(CXX) $(CXXFLAGS) -o $@ $^ $(MEMMGR) $(LDFLAGS) $(LIBS)

test_string: test_string.o string.o $(rtlib) straccum.o compiler.o
    $(CXX) $(CXXFLAGS) -o $@ $^ $(MEMMGR) $(LDFLAGS) $(LIBS)

test_atomics: test_atomics.o string.o straccum.o kvrandom.o $(rtlib) \
    json.o compiler.o kvio.o
    $(CXX) $(CXXFLAGS) -o $@ $^ $(MEMMGR) $(LDFLAGS) $(LIBS)

jsontest: jsontest.o string.o straccum.o json.o compiler.o $(rtlib)
    $(CXX) $(CXXFLAGS) -o $@ $^ $(MEMMGR) $(LDFLAGS) $(LIBS)

msgpacktest: msgpacktest.o string.o straccum.o json.o compiler.o msgpack.o $(rtlib)
    $(CXX) $(CXXFLAGS) -o $@ $^ $(MEMMGR) $(LDFLAGS) $(LIBS)

scantest: scantest.o compiler.o misc.o $(rtlib) $(KVTREES) libjson.a
    $(CXX) $(CXXFLAGS) -o $@ $^ $(MEMMGR) $(LDFLAGS) $(LIBS)

我使用 CC2 和 CXX2 生成经过检测的 .o 文件,而 CC 和 CXX 将它们 link 生成可执行文件。这是我在 运行 make:

时得到的错误

mtd.o: In function main': /home/.../masstree-beta-master/mtd.cc:730: undefined reference tologop' /home/.../masstree-beta-master/mtd.cc:730: undefined reference to logop' /home/.../masstree-beta-master/mtd.cc:732: undefined reference tologop' /home/.../masstree-beta-master/mtd.cc:732: undefined reference to logop' /home/.../masstree-beta-master/mtd.cc:736: undefined reference tologop' mtd.o:/home/.../masstree-beta-master/mtd.cc:736: more undefined references to `logop' follow clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [mtd] Error 1.

即使我在 linking 部分添加了 rtlib.o 以生成可执行文件,为什么对我的函数 logop(在 rtlib.c 中)的引用未定义的任何想法?

非常感谢!

导出的符号不一样。我使用 nm --format sysv *file.o* 检查以确保从 rtlib.o 导出的符号以及它们使用的任何地方都是相同的。