Clang链接错误:LLVM传递添加的对函数调用的未定义引用 [英] Clang Linking error: undefined reference to function calls added by LLVM pass

查看:501
本文介绍了Clang链接错误:LLVM传递添加的对函数调用的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在按照本教程 https://www.cs进行操作. cornell.edu/~asampson/blog/llvm.html 通过添加对外部函数的调用(在rtlib.c中是logop)来传递用于检测程序的传递.但是,与本教程不同的是,我尝试使用更大的代码库masstree: https://github. com/kohler/masstree-beta .

So I am following this tutorial 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)使其与其他.o文件链接以生成可执行文件):

So as instructed for masstree I run ./configure first but then I edit the generated Makefile to use clang (instead of gcc/g++) and run my pass. I also add rtlib.c in the masstree source files so that it gets converted to rtlib.o with the rest of the masstree source files. Here is the relevant part of the modified Makefile with my changes highlighted with an arrow (I also added the $(rtlib) to link it with other .o files to generate executables):

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则将它们链接为可执行文件.这是我运行make时遇到的错误:

I use CC2 and CXX2 to generate the instrumented .o files while CC and CXX to link them into executables. Here is the error I get when I run make:

mtd.o:在功能main': /home/.../masstree-beta-master/mtd.cc:730: undefined reference to logop'中 /home/.../masstree-beta-master/mtd.cc:730:未定义对logop' /home/.../masstree-beta-master/mtd.cc:732: undefined reference to logop的引用 /home/.../masstree-beta-master/mtd.cc:732:未定义对logop' /home/.../masstree-beta-master/mtd.cc:736: undefined reference to logop的引用 mtd.o:/home/.../masstree-beta-master/mtd.cc:736:更多关于`logop'的未定义引用 铛:错误:链接器命令失败,退出代码为1(使用-v查看调用) make:*** [mtd]错误1.

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.

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

Any Idea on why is the reference to my function logop (which is in rtlib.c) undefined even though I add rtlib.o in the linking part to generate executables?

非常感谢您!

推荐答案

导出的符号不同.我使用nm --format sysv *file.o*进行了检查,以确保从rtlib.o导出的符号以及无论在何处使用的符号都是相同的.

The symbol exported were not the same. I checked using nm --format sysv *file.o* to make sure the symbols exported from rtlib.o and wherever they are used is the same.

这篇关于Clang链接错误:LLVM传递添加的对函数调用的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆