Problem linking example program with DataFlow Sanitizer

Hi,

I’m trying to compile the example program from the DataFlow Sanitizer page (http://clang.llvm.org/docs/DataFlowSanitizer.html) without success. I receive a number of errors when trying to compile the example with clang:

/> clang -fsanitize=dataflow -o labelprop labelprop.c
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_info): relocation 19 has invalid symbol index 22
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/Scrt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/…/…/…/x86_64-linux-gnu/Scrt1.o: In function _start': (.text+0x20): undefined reference to main’
/usr/local/llvm/build/Debug+Asserts/bin/…/lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(dfsan_interceptors.o): In function InitializeInterceptors': /usr/local/llvm/projects/compiler-rt/lib/dfsan/dfsan_interceptors.cc:40: undefined reference to __interception::GetRealFunctionAddress(char const*, unsigned long*, unsigned long, unsigned long)’
/usr/local/llvm/projects/compiler-rt/lib/dfsan/dfsan_interceptors.cc:41: undefined reference to __interception::GetRealFunctionAddress(char const*, unsigned long*, unsigned long, unsigned long)' /usr/local/llvm/build/Debug+Asserts/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_deadlock_detector1.o):(.[data.rel.ro](http://data.rel.ro)+0x60): undefined reference to vtable for __cxxabiv1::__si_class_type_info’
/usr/local/llvm/build/Debug+Asserts/bin/…/lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_deadlock_detector1.o):(.data.rel.ro._ZTIN11__sanitizer9DDetectorE[_ZTIN11__sanitizer9DDetectorE]+0x0): undefined reference to vtable for __cxxabiv1::__class_type_info' /usr/local/llvm/build/Debug+Asserts/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_symbolizer.o):(.data.rel.ro._ZTIN11__sanitizer10SymbolizerE[_ZTIN11__sanitizer10SymbolizerE]+0x0): undefined reference to vtable for __cxxabiv1::__class_type_info’
/usr/local/llvm/build/Debug+Asserts/bin/…/lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_symbolizer_posix_libcdep.o):(.data.rel.ro._ZTIN11__sanitizer27ExternalSymbolizerInterfaceE[_ZTIN11__sanitizer27ExternalSymbolizerInterfaceE]+0x0): undefined reference to vtable for __cxxabiv1::__class_type_info' /usr/local/llvm/build/Debug+Asserts/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_symbolizer_posix_libcdep.o):(.data.rel.ro._ZTIN11__sanitizer13Addr2LinePoolE[_ZTIN11__sanitizer13Addr2LinePoolE]+0x0): undefined reference to vtable for __cxxabiv1::__si_class_type_info’
/usr/local/llvm/build/Debug+Asserts/bin/…/lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_symbolizer_posix_libcdep.o):(.data.rel.ro._ZTIN11__sanitizer17SymbolizerProcessE[_ZTIN11__sanitizer17SymbolizerProcessE]+0x0): undefined reference to vtable for __cxxabiv1::__si_class_type_info' /usr/local/llvm/build/Debug+Asserts/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_symbolizer_posix_libcdep.o):(.data.rel.ro._ZTIN11__sanitizer16Addr2LineProcessE[_ZTIN11__sanitizer16Addr2LineProcessE]+0x0): undefined reference to vtable for __cxxabiv1::__si_class_type_info’
/usr/local/llvm/build/Debug+Asserts/bin/…/lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_symbolizer_posix_libcdep.o):(.data.rel.ro._ZTIN11__sanitizer21LLVMSymbolizerProcessE[_ZTIN11__sanitizer21LLVMSymbolizerProcessE]+0x0): undefined reference to vtable for __cxxabiv1::__si_class_type_info' /usr/local/llvm/build/Debug+Asserts/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_symbolizer_posix_libcdep.o):(.data.rel.ro._ZTIN11__sanitizer15POSIXSymbolizerE[_ZTIN11__sanitizer15POSIXSymbolizerE]+0x0): undefined reference to vtable for __cxxabiv1::__si_class_type_info’
/usr/local/llvm/build/Debug+Asserts/bin/…/lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_thread_registry.o):(.data.rel.ro._ZTIN11__sanitizer17ThreadContextBaseE[_ZTIN11__sanitizer17ThreadContextBaseE]+0x0): undefined reference to vtable for __cxxabiv1::__class_type_info' /tmp/labelprop-bfe82e.o: In function dfs$main’:
labelprop.c:(.text+0x78): undefined reference to dfs$dfsan_create_label' labelprop.c:(.text+0xcc): undefined reference to dfs$dfsan_set_label’
labelprop.c:(.text+0x108): undefined reference to dfs$dfsan_create_label' labelprop.c:(.text+0x145): undefined reference to dfs$dfsan_set_label’
labelprop.c:(.text+0x181): undefined reference to dfs$dfsan_create_label' labelprop.c:(.text+0x1bf): undefined reference to dfs$dfsan_set_label’
labelprop.c:(.text+0x2c1): undefined reference to dfs$dfsan_get_label' labelprop.c:(.text+0x303): undefined reference to dfs$dfsan_has_label’
labelprop.c:(.text+0x341): undefined reference to dfs$__assert_fail' labelprop.c:(.text+0x36c): undefined reference to dfs$dfsan_has_label’
labelprop.c:(.text+0x3aa): undefined reference to dfs$__assert_fail' labelprop.c:(.text+0x3d5): undefined reference to dfs$dfsan_has_label’
labelprop.c:(.text+0x413): undefined reference to dfs$__assert_fail' labelprop.c:(.text+0x5e2): undefined reference to dfs$dfsan_get_label’
labelprop.c:(.text+0x624): undefined reference to dfs$dfsan_has_label' labelprop.c:(.text+0x662): undefined reference to dfs$__assert_fail’
labelprop.c:(.text+0x68d): undefined reference to dfs$dfsan_has_label' labelprop.c:(.text+0x6cb): undefined reference to dfs$__assert_fail’
labelprop.c:(.text+0x6f6): undefined reference to dfs$dfsan_has_label' labelprop.c:(.text+0x734): undefined reference to dfs$__assert_fail’
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I also tried to use the prepackaged distribution of clang/llvm for Ubuntu and obtained the same error.

I’m running on Ubuntu Trusty, gcc 4.8.2 and I specified -fsanitize=dataflow when compiling with clang.
Anything wrong? Any help will be appreciated!

Thanks,
Frederico

Hi Frederico,

Hi,

I'm trying to compile the example program from the DataFlow Sanitizer page (
http://clang.llvm.org/docs/DataFlowSanitizer.html) without success. I
receive a number of errors when trying to compile the example with clang:

/> clang -fsanitize=dataflow -o labelprop labelprop.c

[...]

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/Scrt1.o: In
function `_start':
(.text+0x20): undefined reference to `main'

[...]

/tmp/labelprop-bfe82e.o: In function `dfs$main':
labelprop.c:(.text+0x78): undefined reference to `dfs$dfsan_create_label'

It looks like DFSan wasn't able to find the ABI list file. Unfortunately
only the CMake build system currently supports building the ABI list.
Can you please try again with CMake?

/usr/local/llvm/build/Debug+Asserts/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_deadlock_detector1.o):(.data.rel.ro._ZTIN11__sanitizer9DDetectorE[_ZTIN11__sanitizer9DDetectorE]+0x0):
undefined reference to `vtable for __cxxabiv1::__class_type_info'

This would appear to indicate that your sanitizer runtimes were built with
RTTI, which is a little surprising. Did you do anything in particular to
enable RTTI?

Thanks,

Hi Peter,

Thank you for your reply.

I’m still having problems even after using cmake. Please see my comments below.

Hi Peter,

Thank you for your reply.

I'm still having problems even after using cmake. Please see my comments
below.

> Hi Frederico,
>
> > Hi,
> >
> > I'm trying to compile the example program from the DataFlow Sanitizer
> page (
> > http://clang.llvm.org/docs/DataFlowSanitizer.html) without success. I
> > receive a number of errors when trying to compile the example with clang:
> >
> > /> clang -fsanitize=dataflow -o labelprop labelprop.c
> [...]
> > /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/Scrt1.o: In
> > function `_start':
> > (.text+0x20): undefined reference to `main'
> [...]
> > /tmp/labelprop-bfe82e.o: In function `dfs$main':
> > labelprop.c:(.text+0x78): undefined reference to `dfs$dfsan_create_label'
>
> It looks like DFSan wasn't able to find the ABI list file. Unfortunately
> only the CMake build system currently supports building the ABI list.
> Can you please try again with CMake?
>

I created this simple CMake list file:

cmake_minimum_required (VERSION 2.6)
project (EXAMPLE)
add_executable(labelprop labelprop.c)
SET (CMAKE_C_COMPILER "/usr/bin/clang")
SET (CMAKE_C_FLAGS "-fsanitize=dataflow")

After building the project with the above configuration, I still get the
same errors as before. Anything missing? Perhaps I should say that I'm new
to cmake :slight_smile:

Sorry, I meant that you need to compile LLVM/Clang/compiler-rt with CMake
following the instructions here:

http://llvm.org/docs/CMake.html

I forgot to ask in my first email: is there any step-by-step instructions
on how to compile and get the dataflow sanitizer example working?

It shouldn't take any more than compiling with the -fsanitize=dataflow command
line flag, but admittedly the requirement to build Clang with CMake had not
been documented. I'll see about documenting it.

> /usr/local/llvm/build/Debug+Asserts/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_deadlock_detector1.o):(.data.rel.ro._ZTIN11__sanitizer9DDetectorE[_ZTIN11__sanitizer9DDetectorE]+0x0):
> > undefined reference to `vtable for __cxxabiv1::__class_type_info'
>
> This would appear to indicate that your sanitizer runtimes were built with
> RTTI, which is a little surprising. Did you do anything in particular to
> enable RTTI?
>

Well, no. I just followed the instructions on the clang webpage on how to
compile llvm and clang. I used the trunk versions of everything. I also
compiled the optional projects. Could it be the -fsanitizer-dataflow option?

So it looks like when built with Makefiles, the dfsan runtime library contains
some object files that were compiled with RTTI. It isn't immediately clear why
this is happening with dfsan and not with the other sanitizer runtimes. Alexey,
do you have any idea?

In any case, building with CMake should fix this.

Thanks,

> Hi Peter,
>
> Thank you for your reply.
>
> I'm still having problems even after using cmake. Please see my comments
> below.
>
>
> > Hi Frederico,
> >
> > > Hi,
> > >
> > > I'm trying to compile the example program from the DataFlow Sanitizer
> > page (
> > > http://clang.llvm.org/docs/DataFlowSanitizer.html) without success.
I
> > > receive a number of errors when trying to compile the example with
clang:
> > >
> > > /> clang -fsanitize=dataflow -o labelprop labelprop.c
> > [...]
> > > /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/Scrt1.o:
In
> > > function `_start':
> > > (.text+0x20): undefined reference to `main'
> > [...]
> > > /tmp/labelprop-bfe82e.o: In function `dfs$main':
> > > labelprop.c:(.text+0x78): undefined reference to
`dfs$dfsan_create_label'
> >
> > It looks like DFSan wasn't able to find the ABI list file.
Unfortunately
> > only the CMake build system currently supports building the ABI list.
> > Can you please try again with CMake?
> >
>
> I created this simple CMake list file:
>
> cmake_minimum_required (VERSION 2.6)
> project (EXAMPLE)
> add_executable(labelprop labelprop.c)
> SET (CMAKE_C_COMPILER "/usr/bin/clang")
> SET (CMAKE_C_FLAGS "-fsanitize=dataflow")
>
> After building the project with the above configuration, I still get the
> same errors as before. Anything missing? Perhaps I should say that I'm
new
> to cmake :slight_smile:

Sorry, I meant that you need to compile LLVM/Clang/compiler-rt with CMake
following the instructions here:

http://llvm.org/docs/CMake.html

> I forgot to ask in my first email: is there any step-by-step instructions
> on how to compile and get the dataflow sanitizer example working?

It shouldn't take any more than compiling with the -fsanitize=dataflow
command
line flag, but admittedly the requirement to build Clang with CMake had not
been documented. I'll see about documenting it.

> >
/usr/local/llvm/build/Debug+Asserts/bin/../lib/clang/3.5.0/lib/linux/libclang_rt.dfsan-x86_64.a(sanitizer_deadlock_detector1.o):(.data.rel.ro._ZTIN11__sanitizer9DDetectorE[_ZTIN11__sanitizer9DDetectorE]+0x0):
> > > undefined reference to `vtable for __cxxabiv1::__class_type_info'
> >
> > This would appear to indicate that your sanitizer runtimes were built
with
> > RTTI, which is a little surprising. Did you do anything in particular
to
> > enable RTTI?
> >
>
> Well, no. I just followed the instructions on the clang webpage on how to
> compile llvm and clang. I used the trunk versions of everything. I also
> compiled the optional projects. Could it be the -fsanitizer-dataflow
option?

So it looks like when built with Makefiles, the dfsan runtime library
contains
some object files that were compiled with RTTI. It isn't immediately clear
why
this is happening with dfsan and not with the other sanitizer runtimes.
Alexey,
do you have any idea?

r208268 should help.

Thanks!

Hi Peter,

It works! Thanks a lot for your help.

Regards,
Fred