Solved

C++ Text segment relocation error - writing to read only memory

Posted on 2010-09-10
4
752 Views
Last Modified: 2013-11-17
Hey guys,

So... On a pretty beefy project (~15,000 files), I had to start using a new static library.  The static library uses other libraries, etc.  Anyway, everything is in, compliling, etc.

Here's my problem now.  When I run my unit tests on the module using the new library I get a text segment relocation warning followed by a symbol reference and a note of it trying to write to read only memory.

The unit tests literally have nothing whatsoever to do with the portion of the module using the new library (in fact that part isnt even instantiated, the tests are run on a singleton with no dependencies on the part using the library).

Anyway, I'm guessing something about the static libraries is crashing the executable prior to getting to my code, but I don't understand what.  So...

(1) what is a text relocation warning/error?
(2) why would a reference and inclusion to a static library possibly cause one?
(3) why is my executable doing anything with the library when none of its functions or objeects are referenced in the test whatsoever?
(4) why do I ge this error at run instead of compile/link time.

I know that I didn't provide enough information to get specific solutions, but I"m hopeing getting some answers to those 4 questions will help me work this out.  Thanks :)

-w00te
0
Comment
Question by:w00te
  • 2
4 Comments
 
LVL 12

Author Comment

by:w00te
ID: 33647998
PS: The makefile for the test executable does include everything the makefile for the real executable includes, whether or not its used.  That's why the library is part of the build in the first place.

-w00te
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 400 total points
ID: 33652615
>> (1) what is a text relocation warning/error?

It indicates that you're linking to a shared library (loaded at runtime) that is non PIC (position independent code).

In other words : the shared library was not created with -fPIC, so on load time, the dynamic linker has to resolve all the text relocations, by patching the addresses in the code. This involves quite a bit of work (and a slower start of the executable), hence the warning.


>> (2) why would a reference and inclusion to a static library possibly cause one?

Assuming that it is the inclusion of that static library that causes this, I'd say that either :

a) the library is actually a non PIC shared library
b) the library loads in some other shared library that is non PIC


>> (3) why is my executable doing anything with the library when none of its functions or objeects are referenced in the test whatsoever?

If you link to it, then there's a good chance it will be included into the executable (for static libraries) or loaded at runtime (for shared libraries). Static globals eg.

If you could show the exact error message/warning you get, we can be more precise.


>> (4) why do I ge this error at run instead of compile/link time.

Because a shared library is loaded at runtime.
0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 100 total points
ID: 33652679
Never seen this before. But here's a link that may offer more ideas:
    See Displacement Relocations
         http://docs.sun.com/app/docs/doc/817-1984/chapter2-10?l=en&a=view
0
 
LVL 12

Author Closing Comment

by:w00te
ID: 33653464
Thanks guys.  I've been going through the libraries and looking for fPIC compiler options and it seems to be everywhere (I ran into into suggestion online yesterday). Our code base and makefiles makes it a little tough to track everywhere so it may take a while assuming that really is the problem. Were cross compiling to a special unix like system so I'm hoping it's not something strange about the system itself. Anyway, I think this is a god solution for the text relocation issue in general so I'm accepting it.  Thanks for the thoughts :)

-w00te
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Socket Programming (Unix) 8 128
Remove Office macro by VC++ 10 98
How to convert MFC APP to Win32 APP. 19 80
How do i run a c++ file? 15 29
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question