Reputation: 863
I've built a shared library using gcc on Linux (test.so) the code of course is PIC.
one of test.so API calls returns a pointer to a struct on the shared library stack and another call returns a pointer to a struct on the shared library data segment.
When I am trying to access these pointesr after getting them from the shared library I get a SEGFAULT.
My questions are these:
stack addresses should always be valid (as they are calculated as offests to SP) so why did i get a SEGFAULT?
for global addresses, if I access them inside the library the compiler uses a base value given by the dynamic loader to resolve them, but what happens if i do this:
return &x
does the compiler returns the resolved address or does it assume because no LOAD/STORE was executed it can remain the non resolved address?
if it does not resolve the address then the caller might get an offset address instead of a valid address. is this possible?
Upvotes: 0
Views: 207
Reputation: 213706
one of test.so API calls returns a pointer to a struct on the shared library stack
There is no such thing as the "shared library stack". There is only one stack (for each thread), and returning an address of a local variable is almost never what you want.
another call returns a pointer to a struct on the shared library data segment.
That's ok, so long as you don't dlclose()
the library in question.
When I am trying to access these pointesr after getting them from the shared library I get a SEGFAULT.
It is likely that you didn't tell us the whole story, and that your problem is elsewhere.
In any case, given the information you provided a good answer is unlikely. Please edit your question with more details. A test case that can be built and that demonstrates your problem is best.
Upvotes: 1