2

I want to use DRAMSim2 as library interface in a developing PINtool.

I try to be familiar with dramsim_test.cpp that includes dramsim_test.h, that includes DRAMSim.h (in a specific directory).

If i put these files in the directory of my PINtool an include them (except .cpp. for this i use the code in the PINtool) i get a linker (i suppose) error:

undefined symbol: _ZN7DRAMSim23getMemorySystemInstanceERKSsS1_S1_S1_jPSs

The PINtool has a config file that writes these:

## Libraries to link
ifeq ($(TARGET_OS),mac)
    APP_LIBS := -lm
else
    APP_LIBS := -Wl,--as-needed -lm
endif
DL_LIB :=
APP_LIB_ATOMIC := -latomic
APP_LIB_XED := -lxed
TOOL_LIBS := -lpin -lxed
SATOOL_LIBS := -lsapin -lxed
CXX_LIBS :=

The makefile of dramsim example has this:

$(CXX) -g -o dramsim_test dramsim_test.cpp -I../ -L../ -ldramsim -Wl,-rpath=../

I suppose that i have to add somewhere in the pintool config file the -ldramism option but i dont know how.

Im not familiar also with linker options, configuration files etc. How can i link them?

UPDATE: The problem solved. After changing the conf file by adding -ldramsim and didnt work, i tried to move the libdramsim.so into the folder of allcache_v7.cpp and is ok...

Orion Papadakis
  • 398
  • 1
  • 14

1 Answers1

2

Just add -ldramsim to the TOOL_LIBS variable. You will also need to add its path. So change the line:

TOOL_LIBS := -lpin -lxed

to

TOOL_LIBS := -lpin -lxed -L/path/to/dramsim/ -ldramsim

UPDATE: Now that you have successfully built your library, you're almost there. You just need to make sure it is found by the dynamic linker at load time. In theory, this is done as follows from your shell prompt:

> export LD_LIBRARY_PATH=/path/to/dramsim:${LD_LIBRARY_PATH}
> #command to invoke binary that uses your library allcache_v7.so

If this still gives you problems, check if the linker can resolve it:

> ldd allcache_v7.so | grep dramsim

This should tell you whether the linker can resolve libdramsin.so or not. Try it before and after the export ... command - see if the output changes from something like "Not found" to the true path of the library.

Smeeheey
  • 9,906
  • 23
  • 39
  • thank you for your answer... but the problem still exists. I changed the line you said and didnt work. I also tried to change this: CXX_LPATHS := -I ../../../DRAMSim2/ -L ../../../DRAMSim2/ (the paths are correct but i dont know how to use -I and -L) – Orion Papadakis Jun 08 '16 at 16:13
  • Can you get your PINTool build to be verbose, so it outputs the compiler command line(s) it uses, and share this? – Smeeheey Jun 08 '16 at 16:15
  • `g++ -DBIGARRAY_MULTIPLIER=1 -Wall -Werror -Wno-unknown-pragmas -fno-stack-protector -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_LINUX -I../../../source/include/pin -I../../../source/include/pin/gen -I../../../extras/components/include -I../../../extras/xed-intel64/include -I../../../source/tools/InstLib -O3 -fomit-frame-pointer -fno-strict-aliasing -c -o obj-intel64/allcache_v7.o allcache_v7.cpp` – Orion Papadakis Jun 08 '16 at 16:20
  • and also: `g++ -shared -Wl,--hash-style=sysv -Wl,-Bsymbolic -Wl,--version-script=../../../source/include/pin/pintool.ver -o obj-intel64/allcache_v7.so obj-intel64/allcache_v7.o -L../../../intel64/lib -L../../../intel64/lib-ext -L../../../intel64/runtime/glibc -L../../../extras/xed-intel64/lib -lpin -lxed -lpindwarf -ldl` – Orion Papadakis Jun 08 '16 at 16:20
  • OK. I think try this: instead of adding `-ldramsim` to `CXX_LIBS`, add it to `TOOL_LIBS` instead. So the relevant line becomes `TOOL_LIBS := -lpin -lxed -ldramsim` – Smeeheey Jun 08 '16 at 16:23
  • Can you dump your gcc lines again? Have they changed? – Smeeheey Jun 08 '16 at 16:33
  • /usr/bin/ld: cannot find -ldramsim collect2: error: ld returned 1 exit status – Orion Papadakis Jun 08 '16 at 16:37
  • Aha! That's progress! Now all you need to do is add the search path for that library. Assuming you know where the `libdramsim.so` is located, and this is at say `/path/to/dramsim/libdramsim.so`, just modify your `TOOL_LIBS` variable further like this: `TOOL_LIBS := -lpin -lxed -L/path/to/dramsim/ -ldramsim` – Smeeheey Jun 08 '16 at 16:41
  • the error still exists... (library directory is 100% correct) `E: Unable to load /home/taleporos/Dropbox/PIN/source/tools/MemTrace/obj-intel64/allcache_v7.so: libdramsim.so: cannot open shared object file: No such file or directory` – Orion Papadakis Jun 08 '16 at 17:06
  • Can you please repost the current gcc compile (note: not error) lines? – Smeeheey Jun 08 '16 at 17:10
  • Hang on sorry... The above error that you posted - does this mean you're no longer getting the `/usr/bin/ld: cannot find ...` error? – Smeeheey Jun 08 '16 at 17:12
  • `g++ -DBIGARRAY_MULTIPLIER=1 -Wall -Werror -Wno-unknown-pragmas -fno-stack-protector -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_LINUX -I../../../source/include/pin -I../../../source/include/pin/gen -I../../../extras/components/include -I../../../extras/xed-intel64/include -I../../../source/tools/InstLib -O3 -fomit-frame-pointer -fno-strict-aliasing -c -o obj-intel64/allcache_v7.o allcache_v7.cpp` – Orion Papadakis Jun 08 '16 at 17:13
  • `g++ -shared -Wl,--hash-style=sysv -Wl,-Bsymbolic -Wl,--version-script=../../../source/include/pin/pintool.ver -o obj-intel64/allcache_v7.so obj-intel64/allcache_v7.o -L../../../intel64/lib -L../../../intel64/lib-ext -L../../../intel64/runtime/glibc -L../../../extras/xed-intel64/lib -lpin -lxed -I../../../DRAMSim2 -L../../../DRAMSim2 -ldramsim -lpindwarf -ldl` – Orion Papadakis Jun 08 '16 at 17:13
  • Thanks, please also answer my later comment – Smeeheey Jun 08 '16 at 17:14
  • Your observation is correct! before:`/usr/bin/ld: cannot find -ldramsim` now:`E: Unable to load /home/taleporos/Dropbox/PIN/source/tools/MemTrace/obj-intel64/allcache_v7.so: libdramsim.so: cannot open shared object file: No such file or directory` – Orion Papadakis Jun 08 '16 at 17:19
  • If the answer is yes, which I suspect it is, I think you've now successfully built your library, and your latest problem is now actually loading it. I suggest try this: before running whatever commands you run, in the shell where you're running them type `export LD_LIBRARY_PATH=/path/to/dramsim` using the full path to `libdramsim.so`'s directory – Smeeheey Jun 08 '16 at 17:20
  • i did the export but nothing happened again... :-( – Orion Papadakis Jun 08 '16 at 17:28
  • Can you please try all of the steps in my update to the answer above and see where you get? – Smeeheey Jun 08 '16 at 19:19
  • after ldd allcache_v7.so | grep dramsim `libdramsim.so => /home/taleporos/Dropbox/PIN/DRAMSim2/libdramsim.so (0x00007f9df1bda000)` but the problem still cannot open shared object file: no such file or directory – Orion Papadakis Jun 08 '16 at 21:06
  • Can you please share the command line that is actually invoking the application that uses your built library `allcache_v7.so`? – Smeeheey Jun 09 '16 at 12:18