PATCH: Support DF_TEXTREL/DT_TEXTREL for SVR4 mips
H . J . Lu
hjl@lucon.org
Sat Jun 16 09:30:00 GMT 2001
On Sat, Jun 16, 2001 at 02:18:39PM +0100, Nick Clifton wrote:
> Hi H.J.
>
> > > Is it safe to just check SEC_READONLY ? Shouldn't you also check for
> > > SEC_CODE ?
> >
>
It turns out that we should check some additional bits. Here is an
example.
NXConstStr.o: file format elf32-tradlittlemips
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 000000a0 0000000000000000 0000000000000000 00000040 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 000000e0 0000000000000000 0000000000000000 000000e0 2**4
CONTENTS, ALLOC, LOAD, RELOC, DATA
2 .bss 00000000 0000000000000000 0000000000000000 000001c0 2**4
ALLOC
3 .reginfo 00000018 0000000000000000 0000000000000000 000001c0 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA, LINK_ONCE_SAME_SIZE
4 .pdr 00000060 0000000000000000 0000000000000000 000001d8 2**2
CONTENTS, RELOC, READONLY
5 .note 00000014 0000000000000000 0000000000000000 00000238 2**0
CONTENTS, READONLY
6 .stab 00000e10 0000000000000000 0000000000000000 0000024c 2**2
CONTENTS, RELOC, READONLY, DEBUGGING
7 .stabstr 00003915 0000000000000000 0000000000000000 0000105c 2**0
CONTENTS, READONLY, DEBUGGING
8 .ctors 00000004 0000000000000000 0000000000000000 00004974 2**2
CONTENTS, ALLOC, LOAD, RELOC, DATA
9 .rodata 000000a0 0000000000000000 0000000000000000 00004980 2**4
CONTENTS, ALLOC, LOAD, READONLY, DATA
We don't care relocations against .pdr nor .stab sections. Also my
previous patch doesn't cover the executables. Here is an updated one.
Thanks.
H.J.
---
2001-06-16 H.J. Lu <hjl@gnu.org>
* elf32-mips.c (mips_elf_link_hash_entry): Add a new field,
readonly_reloc, to record if a relocation in the .rel.dyn
section is against a read-only section.
(mips_elf_link_hash_newfunc): Initialize the readonly_reloc
field to false.
(_bfd_mips_elf_check_relocs): Record if there is a relocation
in the .rel.dyn section against a read-only section by setting
DF_TEXTREL or readonly_reloc.
(_bfd_mips_elf_copy_indirect_symbol): Copy readonly_reloc if
it is true.
(_bfd_mips_elf_adjust_dynamic_symbol): Record DF_TEXTREL if
there is a relocation in the .rel.dyn section against a
read-only section.
(_bfd_mips_elf_size_dynamic_sections): Set DT_TEXTREL if
DF_TEXTREL is set.
--- bfd/elf32-mips.c.rodata Sat Jun 16 08:19:56 2001
+++ bfd/elf32-mips.c Sat Jun 16 08:49:07 2001
@@ -76,6 +76,10 @@ struct mips_elf_link_hash_entry
this symbol. */
unsigned int possibly_dynamic_relocs;
+ /* If the R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 reloc is against
+ a readonly section. */
+ boolean readonly_reloc;
+
/* The index of the first dynamic relocation (in the .rel.dyn
section) against this symbol. */
unsigned int min_dyn_reloc_index;
@@ -4014,6 +4018,7 @@ mips_elf_link_hash_newfunc (entry, table
not been set. -1 means there is no associated ifd. */
ret->esym.ifd = -2;
ret->possibly_dynamic_relocs = 0;
+ ret->readonly_reloc = false;
ret->min_dyn_reloc_index = 0;
ret->no_fn_stub = false;
ret->fn_stub = NULL;
@@ -7882,12 +7887,20 @@ _bfd_mips_elf_check_relocs (abfd, info,
return false;
}
}
+#define MIPS_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
if (info->shared)
- /* When creating a shared object, we must copy these
- reloc types into the output file as R_MIPS_REL32
- relocs. We make room for this reloc in the
- .rel.dyn reloc section. */
- mips_elf_allocate_dynamic_relocations (dynobj, 1);
+ {
+ /* When creating a shared object, we must copy these
+ reloc types into the output file as R_MIPS_REL32
+ relocs. We make room for this reloc in the
+ .rel.dyn reloc section. */
+ mips_elf_allocate_dynamic_relocations (dynobj, 1);
+ if ((sec->flags & MIPS_READONLY_SECTION)
+ == MIPS_READONLY_SECTION)
+ /* We tell the dynamic linker that there are
+ relocations against the text segment. */
+ info->flags |= DF_TEXTREL;
+ }
else
{
struct mips_elf_link_hash_entry *hmips;
@@ -7896,6 +7909,11 @@ _bfd_mips_elf_check_relocs (abfd, info,
defined in a dynamic object. */
hmips = (struct mips_elf_link_hash_entry *) h;
++hmips->possibly_dynamic_relocs;
+ if ((sec->flags & MIPS_READONLY_SECTION)
+ == MIPS_READONLY_SECTION)
+ /* We need it to tell the dynamic linker if there
+ are relocations against the text segment. */
+ hmips->readonly_reloc = true;
}
/* Even though we don't directly need a GOT entry for
@@ -8089,6 +8107,8 @@ _bfd_mips_elf_copy_indirect_symbol (dir,
dirmips = (struct mips_elf_link_hash_entry *) dir;
indmips = (struct mips_elf_link_hash_entry *) ind;
dirmips->possibly_dynamic_relocs += indmips->possibly_dynamic_relocs;
+ if (indmips->readonly_reloc)
+ dirmips->readonly_reloc = true;
if (dirmips->min_dyn_reloc_index == 0
|| (indmips->min_dyn_reloc_index != 0
&& indmips->min_dyn_reloc_index < dirmips->min_dyn_reloc_index))
@@ -8132,8 +8152,14 @@ _bfd_mips_elf_adjust_dynamic_symbol (inf
if (! info->relocateable
&& hmips->possibly_dynamic_relocs != 0
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
- mips_elf_allocate_dynamic_relocations (dynobj,
- hmips->possibly_dynamic_relocs);
+ {
+ mips_elf_allocate_dynamic_relocations (dynobj,
+ hmips->possibly_dynamic_relocs);
+ if (hmips->readonly_reloc)
+ /* We tell the dynamic linker that there are relocations
+ against the text segment. */
+ info->flags |= DF_TEXTREL;
+ }
/* For a function, create a stub, if allowed. */
if (! hmips->no_fn_stub
@@ -8493,11 +8519,14 @@ _bfd_mips_elf_size_dynamic_sections (out
return false;
}
}
+
if (reltext && SGI_COMPAT (output_bfd))
+ info->flags |= DF_TEXTREL;
+
+ if ((info->flags & DF_TEXTREL) != 0)
{
if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0))
return false;
- info->flags |= DF_TEXTREL;
}
if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0))
More information about the Binutils
mailing list