This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

__builtin_return_address in dlsym.c




Hello,
I found an interessting problem in dlsym.c for the S/390 architecture (but
other architectures might have a hit too). The story starts with the usage
of __builtin_return_address to get an address inside the function of the
caller. This information is used to find the object the caller belongs to.
The problem on S/390 is that the instruction used to call dlsym (BASR -
branch an save register) sets the high order bit in the return register
(that has to do with the addressing mode and other lovely S/390 stuff). So
you get 0xC000071C instead of 0x4000071c. The search for the shared object
fails because the address with the high order bit doesn't point to anything
usefull. The end of the story is a segmentation fault.
We took a look into the gcc code to correct the address returned       by
__builtin_return_address (just strip the high order bit). This didn't work
but we found another interessting function: __builtin_extract_return_addr.
The idea seems to be that __builtin_return_address returns something that
can be used as a return address or branch target but there could be some
"strange" bits that doesn't effect the branch but they will effect
compares. __builtin_extract_return_addr is used to removed these additional
bits.
What I did to fix the dlsym bug for S/390 was to replace every call to
__builtin_return_address(?) by
__builtin_extract_return_addr(__builtin_return_address(?)).

Now the question: is this safe to do for all architectures ?

blue skies,
   Martin

P.S. by the way there is another function __builtin_frob_return_addr that
can add bits to an address again.

Linux/390 Design & Development, IBM Deutschland Entwicklung GmbH
Schönaicherstr. 220, D-71032 Böblingen, Telefon: 49 - (0)7031 - 16-2247
E-Mail: schwidefsky@de.ibm.com



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]