4

My application uses my shared library. Application and library must be mudflapped to check out of bounds reads and writes both on stack and heap. Shared library was successfully build, but while linking application I had a lot of errors.

I made a simple example that reproduces this issue. Here are steps to reproduce:

  • create C++ dynamic shared library project with 2 files: h and cpp files with some class, and in h or cpp file use #include <iostream>
  • create C++ application that uses this library (uses class from inside shared library)
  • build library
  • build application (here you will catch an linking error)

Here are my files:

SharedLibTest.h

#ifndef SHAREDLIBTEST_H_
#define SHAREDLIBTEST_H_

#include <iostream>

class SharedLibTest {
public:
    void func();
};

#endif /* SHAREDLIBTEST_H_ */

SharedLibTest.cpp

#include "SharedLibTest.h"

void SharedLibTest::func()
{}

main.cpp

#include <SharedLibTest.h>

int main(int argc, char *argv[])
{
    SharedLibTest obj;
    obj.func();

    return 0;
}

Building the library:

g++ -O0 -g3 -Wall -c -fmessage-length=0 -fmudflap -funwind-tables -fPIC -MMD -MP -MF"SharedLibTest.d" -MT"SharedLibTest.d" -o "SharedLibTest.o" "../SharedLibTest.cpp"
g++ -rdynamic -shared -o "libshared_lib.so"  ./SharedLibTest.o   -lmudflap

Building the application:

g++ -I"/home/msviridov/work/prj/workspace/shared_lib" -O0 -g3 -Wall -c -fmessage-length=0 -fmudflap -funwind-tables -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
g++ -L"/home/msviridov/work/prj/workspace/shared_lib/Debug" -rdynamic -v -o "executable"  ./main.o   -lshared_lib -lmudflap

Linker error output is:

/home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<unsigned long>::__digits'
/home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<long>::__min'
/home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<short>::__min'
/home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<char>::__max'
/home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<short>::__max'
/home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<long>::__max'
/home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<int>::__max'
/home/msviridov/work/prj/workspace/shared_lib/Debug/libshared_lib.so: undefined reference to `__gnu_cxx::__numeric_traits_integer<int>::__min'
collect2: ld returned 1 exit status
make: *** [executable] Error 1

Though, if I remove mudflap compiler and linker flags for library the build of application will finish successfully. But it's not true for vice versa.

I don't understand what does lead to such result. My platform is Linux Mint 13 Maya 64 bit. I'll appreciate any help. Thanks.

4

2 回答 2

3

#include <iostream>从头文件中删除。如果你想iostream在你的源文件 (SharedLibTest.cpp) 中包含它。

将它包含在头文件中也会给您带来很多垃圾,并且还可能导致一些类似的引用错误。创建 SharedLibTest.o 而不包含并比较目标文件的大小。

于 2012-12-04T21:54:45.027 回答
0

您可能遇到了错误 53359,但您需要最近的 4.8 代码来检查。此外,请注意,mudflap 适用于C 和非常简单的 C++ 程序,因此您可能会发现误报(ala bug 19319)并且它还不适用于 DSO

于 2013-02-14T12:28:59.823 回答