<div dir="ltr">Hi all,<div><br></div><div>I have been stuck on this error for long now and I really need help!.</div><div><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">So I am following this tutorial <a href="https://www.cs.cornell.edu/~asampson/blog/llvm.html" rel="nofollow noreferrer" style="margin:0px;padding:0px;border:0px;color:rgb(0,89,153);text-decoration:none">https://www.cs.cornell.edu/~asampson/blog/llvm.html</a> 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:<a href="https://github.com/kohler/masstree-beta" rel="nofollow noreferrer" style="margin:0px;padding:0px;border:0px;color:rgb(0,89,153);text-decoration:none">https://github.com/kohler/masstree-beta</a>.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">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):</p><pre style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);word-wrap:normal;color:rgb(36,39,41)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;white-space:inherit">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)</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">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:</p><blockquote style="margin:0px 0px 10px;padding:10px;border-width:0px 0px 0px 2px;border-top-style:initial;border-right-style:initial;border-bottom-style:initial;border-left-style:solid;border-top-color:initial;border-right-color:initial;border-bottom-color:initial;border-left-color:rgb(255,235,142);font-size:15px;quotes:none;background-color:rgb(255,248,220);color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif"><p style="margin:0px;padding:0px;border:0px;clear:both">mtd.o: In function <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">main':
/home/.../masstree-beta-master/mtd.cc:730: undefined reference to</code>logop' /home/.../masstree-beta-master/mtd.cc:730: undefined reference to <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">logop'
/home/.../masstree-beta-master/mtd.cc:732: undefined reference to</code>logop' /home/.../masstree-beta-master/mtd.cc:732: undefined reference to <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);white-space:pre-wrap">logop'
/home/.../masstree-beta-master/mtd.cc:736: undefined reference to</code>logop' 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.</p></blockquote><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">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?<br><br>The question is posted on StackOverflow as well: <a href="http://stackoverflow.com/questions/41650417/clang-linking-error-undefined-reference-to-function-calls-added-by-llvm-pass">http://stackoverflow.com/questions/41650417/clang-linking-error-undefined-reference-to-function-calls-added-by-llvm-pass</a></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">Please help! Thank you so much!</p></div></div>