This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: DT_TEXTREL
- To: amodra at one dot net dot au, cburgess at qnx dot com
- Subject: Re: DT_TEXTREL
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- Date: Wed, 16 May 2001 05:52:10 +0200
- CC: binutils at sources dot redhat dot com
> From: amodra@one.net.au
> Date: Tue, 15 May 2001 13:29:58 +0930
> On Mon, May 14, 2001 at 11:06:24AM -0400, Colin Burgess wrote:
> > There seems to be a problem in the elf linker where a DT_TEXTREL is
> > not being created when a .rel.text is present. This is because the
> > .text segment is marked as writeable until the last minute when
> > config.text_read_only is checked.
> Please tell us the version of binutils, and the target you are
> talking about.
Definitely. *Always provide enough information so the problem
can be observed by anyone*. The route from problem description
to repeating it is almost *always* much longer than from
repetition to solution. Oh, sorry, that became a rant. ;-)
> Your problem is quite likely target-specific.
Partly yes; with a mainstream elfNN-blah.c it can depend on the
ld-script. A problem matching the description can be repeated
on i.86-pc-linux-gnu if you tweak ld/emulparams/elf_i386.sh by
adding e.g. TEXT_START_SYMBOLS='PROVIDE(__Whatever = .);'
That assignment causes this piece of code from
ldlang.c:wild_doit (around 1179) to filter out SEC_READONLY
(first == false), so elf_i386_size_dynamic_sections does not
recognize .text as such, so does not add a DT_TEXTREL:
/* If this is not the first input section, and the SEC_READONLY
flag is not currently set, then don't set it just because the
input section has it set. */
if (! first && (section->output_section->flags & SEC_READONLY) == 0)
flags &= ~ SEC_READONLY;
Sorry, I haven't investigated further. Though I don't
understand why SEC_READONLY is filtered out above at all; that
seems bogus to me. Can someone explain? Or perhaps the code
above and neighboring code should be moved to init_os or
something. Ghastly confession: I worked around that bug in
elf32-cris.c:elf_cris_size_dynamic_sections and did not follow
up.
Anyway, here's a testcase that exposes the problem at least on
i686-pc-linux-gnu with the tweak to elf_i386.sh above. I will
probably not revisit this problem for some weeks.
textrel.s:
.text
here:
.long externsym
as-new -o textrel.o textrel.s
ld-new -shared -o textrel textrel.o
Note the absence of DT_TEXTREL in "textrel":
Dynamic segment at offset 0x290 contains 9 entries:
Tag Type Name/Value
0x00000004 (HASH) 0x94
0x00000005 (STRTAB) 0x234
0x00000006 (SYMTAB) 0x124
0x0000000a (STRSZ) 66 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000011 (REL) 0x278
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000000 (NULL) 0x0
With untweaked elf_i386.sh you get the expected:
Dynamic segment at offset 0x290 contains 10 entries:
Tag Type Name/Value
0x00000004 (HASH) 0x94
0x00000005 (STRTAB) 0x234
0x00000006 (SYMTAB) 0x124
0x0000000a (STRSZ) 66 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000011 (REL) 0x278
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000016 (TEXTREL) 0x0
0x00000000 (NULL) 0x0
brgds, H-P