nommu handling of DT_TEXTREL

Bernd Schmidt bernds at codesourcery.com
Fri Apr 1 13:06:55 UTC 2011


We have a problem with DT_TEXTREL shared libraries on nommu machines.
The dynamic linker's strategy is to map the text segment read-only
first, then look for DT_TEXTREL, and use mprotect to change protections
if necessary. This fails on nommu, since a nommu kernel can decide to
share the memory for private read-only file mappings, and mprotect
doesn't (can't) do anything about this sharing. Existing nommu targets
apparently have no need for this, but on C6X, we may need to assign
library indices at run-time if no --dsbt-index option was passed to the
linker at build time.

Hence, the following patch, which instead of using mprotect, redoes the
mapping with PF_W set.

As a test, I've changed librt.so not to have a DSBT index (so that we
get DSBT_INDEX relocs and DT_TEXTREL), and run two copies of a program
that uses this library in parallel:

(A)

/home/bernds # LD_DEBUG=1 ./clocktst
_dl_get_ready_to_run:779: 	file='librt.so.0';  needed by './clocktst'
_dl_load_shared_library:212: 	find library='librt.so.0'; searching
_dl_load_shared_library:289: 	searching ldso dir='/lib'
0: mapped 0x0 at 0xe7770000, size 0x116c
1: mapped 0x216c at 0xe788f16c, size 0x204
1: changed mapping 0x0 at 0xe77b4000 (old 0xe7770000), size 0x116c

_dl_get_ready_to_run:779: 	file='libc.so.0';  needed by './clocktst'
_dl_load_shared_library:212: 	find library='libc.so.0'; searching
_dl_load_shared_library:289: 	searching ldso dir='/lib'
0: mapped 0x0 at 0xe7800000, size 0x71d88
1: mapped 0x72d88 at 0xe77f8d88, size 0x3d98

(B)

/home/bernds # LD_DEBUG=1 ./clocktst
_dl_get_ready_to_run:779: 	file='librt.so.0';  needed by './clocktst'
_dl_load_shared_library:212: 	find library='librt.so.0'; searching
_dl_load_shared_library:289: 	searching ldso dir='/lib'
0: mapped 0x0 at 0xe7770000, size 0x116c
1: mapped 0x216c at 0xe76f916c, size 0x204
1: changed mapping 0x0 at 0xe788c000 (old 0xe7770000), size 0x116c

_dl_get_ready_to_run:779: 	file='libc.so.0';  needed by './clocktst'
_dl_load_shared_library:212: 	find library='libc.so.0'; searching
_dl_load_shared_library:289: 	searching ldso dir='/lib'
0: mapped 0x0 at 0xe7800000, size 0x71d88
1: mapped 0x72d88 at 0xe7758d88, size 0x3d98

That seems to demonstrate both the problem (identical initial mappings
for segment 0 of librt.so) and the fix.

Ok to install?


Bernd
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nommu-textrel.diff
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20110401/b0fbce8b/attachment.diff>


More information about the uClibc mailing list