PATCH: fix invalid load module complaint from dld.sl under hppa64-hp-hpux11
John David Anglin
dave@hiauly1.hia.nrc.ca
Sat Jun 15 12:12:00 GMT 2002
> This fixed the segfault problem but dld.sl is complaining the shared
> libraries are not valid load modules. The test program works
> okay though. ldd also complains, so maybe I'll try to hunt the problem
> down that way or using dlopen.
This patch fixes the invalid load module complaint from dld.sl. The
problem was __gp was being computed incorrectly when a section was
stripped from the output.
The first approach that I tried to fix the problem was to set
hppa_info->plt_sec and the other section pointers maintained in
hppa_info to NULL when the corresponding section was stripped
from the output so that the checks in elf_hppa_final_link would
work. This exposed a problem in elf_hppa_final_link_relocate.
We were incorrectly using the .opd section to compute the relocation
value for symbols where we didn't want an opd entry. In testing,
I found other uses of hppa_info->opd_sec without a check to
see if the pointer is NULL. I think these are harmless but
possibly I should have persevered and added the checks.
In the patch presented here, I just added checks in elf_hppa_final_link
to see if a section has been excluded before using to compute __gp.
I also fixed the opd entry use problem in elf_hppa_final_link_relocate.
The changes to elf64-hppa.c are mainly cosmetic. I simplified a
couple of code snippets. I moved a number of comments regarding the
stripping of sections in elf64_hppa_size_dynamic_sections because
_bfd_strip_section_from_output unconditionally removes a section
from the output. It also conditionally removes the output section
for the section if it becomes empty. I broke up the assert in
elf64_hppa_size_dynamic_sections because it caused problems when
I tried resetting the hppa_info pointers.
I have tested the patch with builds and regression checks under
hppa64-hp-hpux11* and hppa2.0w-hp-hpux11.00. I also have bootstrapped
gcc 3.1.1 with and without "--enable-shared" on hppa64-hp-hpux11.11.
There is no difference in test results except for the objc results
where all execution tests fail with "--enable-shared". For example,
Executing on host: /xxx/gnu/gcc-3.2/objdir/gcc/xgcc -B/xxx/gnu/gcc-3.2/objdir/gc
c/ /xxx/gnu/gcc-3.2/gcc/gcc/testsuite/objc/execute/_cmd.m -w -O0 -I/xxx/gnu/g
cc-3.2/gcc/gcc/testsuite/../../libobjc -L/xxx/gnu/gcc-3.2/objdir/hppa64-hp-hpux1
1.00/libobjc/.libs -lobjc -lm -o /xxx/gnu/gcc-3.2/objdir/gcc/testsuite/_cmd.x
0 (timeout = 300)
PASS: objc/execute/_cmd.m compilation, -O0
objc runtime: cannot find class Object
FAIL: objc/execute/_cmd.m execution, -O0
The objc fails are not new.
Please install if OK.
Dave
--
J. David Anglin dave.anglin@nrc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6605)
2002-06-15 John David Anglin <dave@hiauly1.hia.nrc.ca>
* elf-hppa.h (elf_hppa_final_link): Fix formatting in comment.
Skip excluded sections in determing __gp value.
(elf_hppa_final_link_relocate): Use the symbol's address in
R_PARISC_FPTR64 relocations that don't need an opd entry.
* elf64-hppa.c (allocate_dynrel_entries): Simplify code.
(elf64_hppa_finalize_dynreloc): Likewise.
(elf64_hppa_size_dynamic_sections): Move comments and fix typo.
(elf64_hppa_finish_dynamic_symbol): Break up assert.
Index: elf-hppa.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-hppa.h,v
retrieving revision 1.56
diff -u -3 -p -r1.56 elf-hppa.h
--- elf-hppa.h 8 Apr 2002 11:01:43 -0000 1.56
+++ elf-hppa.h 15 Jun 2002 16:34:41 -0000
@@ -1296,22 +1296,22 @@ elf_hppa_final_link (abfd, info)
address of the .plt + gp_offset.
If no .plt is found, then look for .dlt, .opd and .data (in
- that order) and set __gp to the base address of whichever section
- is found first. */
+ that order) and set __gp to the base address of whichever
+ section is found first. */
sec = hppa_info->plt_sec;
- if (sec)
+ if (sec && ! (sec->flags & SEC_EXCLUDE))
gp_val = (sec->output_offset
+ sec->output_section->vma
+ hppa_info->gp_offset);
else
{
sec = hppa_info->dlt_sec;
- if (!sec)
+ if (!sec || (sec->flags & SEC_EXCLUDE))
sec = hppa_info->opd_sec;
- if (!sec)
+ if (!sec || (sec->flags & SEC_EXCLUDE))
sec = bfd_get_section_by_name (abfd, ".data");
- if (!sec)
+ if (!sec || (sec->flags & SEC_EXCLUDE))
return false;
gp_val = sec->output_offset + sec->output_section->vma;
@@ -2074,11 +2074,14 @@ elf_hppa_final_link_relocate (rel, input
hppa_info->opd_sec->contents + dyn_h->opd_offset + 24);
}
- /* We want the value of the OPD offset for this symbol, not
- the symbol's actual address. */
- value = (dyn_h->opd_offset
- + hppa_info->opd_sec->output_offset
- + hppa_info->opd_sec->output_section->vma);
+ if (dyn_h->want_opd)
+ /* We want the value of the OPD offset for this symbol. */
+ value = (dyn_h->opd_offset
+ + hppa_info->opd_sec->output_offset
+ + hppa_info->opd_sec->output_section->vma);
+ else
+ /* We want the address of the symbol. */
+ value += addend;
bfd_put_64 (input_bfd, value, hit_data);
return bfd_reloc_ok;
Index: elf64-hppa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-hppa.c,v
retrieving revision 1.22
diff -u -3 -p -r1.22 elf64-hppa.c
--- elf64-hppa.c 12 Jun 2002 18:12:25 -0000 1.22
+++ elf64-hppa.c 15 Jun 2002 16:34:42 -0000
@@ -1532,15 +1532,11 @@ allocate_dynrel_entries (dyn_h, data)
for (rent = dyn_h->reloc_entries; rent; rent = rent->next)
{
- switch (rent->type)
- {
- case R_PARISC_FPTR64:
- /* Allocate one iff we are building a shared library and don't
- want an opd entry. */
- if (!x->info->shared && dyn_h->want_opd)
- continue;
- break;
- }
+ /* Allocate one iff we are building a shared library, the relocation
+ isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
+ if (!shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
+ continue;
+
hppa_info->other_rel_sec->_raw_size += sizeof (Elf64_External_Rela);
/* Make sure this symbol gets into the dynamic symbol table if it is
@@ -1722,10 +1718,9 @@ elf64_hppa_size_dynamic_sections (output
if (strcmp (name, ".plt") == 0)
{
+ /* Strip this section if we don't need it; see the comment below. */
if (s->_raw_size == 0)
{
- /* Strip this section if we don't need it; see the
- comment below. */
strip = true;
}
else
@@ -1736,24 +1731,29 @@ elf64_hppa_size_dynamic_sections (output
}
else if (strcmp (name, ".dlt") == 0)
{
+ /* Strip this section if we don't need it; see the comment below. */
if (s->_raw_size == 0)
{
- /* Strip this section if we don't need it; see the
- comment below. */
strip = true;
}
}
else if (strcmp (name, ".opd") == 0)
{
+ /* Strip this section if we don't need it; see the comment below. */
if (s->_raw_size == 0)
{
- /* Strip this section if we don't need it; see the
- comment below. */
strip = true;
}
}
- else if (strncmp (name, ".rela", 4) == 0)
+ else if (strncmp (name, ".rela", 5) == 0)
{
+ /* If we don't need this section, strip it from the output file.
+ This is mostly to handle .rela.bss and .rela.plt. We must
+ create both sections in create_dynamic_sections, because they
+ must be created before the linker maps input sections to output
+ sections. The linker does that before adjust_dynamic_symbol
+ is called, and it is that function which decides whether
+ anything needs to go into these sections. */
if (s->_raw_size == 0)
{
/* If we don't need this section, strip it from the
@@ -1951,9 +1951,6 @@ elf64_hppa_finish_dynamic_symbol (output
spltrel = hppa_info->plt_rel_sec;
sdltrel = hppa_info->dlt_rel_sec;
- BFD_ASSERT (stub != NULL && splt != NULL
- && sopd != NULL && sdlt != NULL)
-
/* Incredible. It is actually necessary to NOT use the symbol's real
value when building the dynamic symbol table for a shared library.
At least for symbols that refer to functions.
@@ -1963,6 +1960,8 @@ elf64_hppa_finish_dynamic_symbol (output
the original values (in elf64_hppa_link_output_symbol_hook). */
if (dyn_h && dyn_h->want_opd)
{
+ BFD_ASSERT (sopd != NULL)
+
/* Save away the original value and section index so that we
can restore them later. */
dyn_h->st_value = sym->st_value;
@@ -1984,6 +1983,8 @@ elf64_hppa_finish_dynamic_symbol (output
bfd_vma value;
Elf_Internal_Rela rel;
+ BFD_ASSERT (splt != NULL && spltrel != NULL)
+
/* We do not actually care about the value in the PLT entry
if we are creating a shared library and the symbol is
still undefined, we create a dynamic relocation to fill
@@ -2034,6 +2035,8 @@ elf64_hppa_finish_dynamic_symbol (output
int insn;
unsigned int max_offset;
+ BFD_ASSERT (stub != NULL)
+
/* Install the generic stub template.
We are modifying the contents of the stub section, so we do not
@@ -2357,15 +2360,10 @@ elf64_hppa_finalize_dynreloc (dyn_h, dat
{
Elf64_Internal_Rela rel;
- switch (rent->type)
- {
- case R_PARISC_FPTR64:
- /* Allocate one iff we are building a shared library and don't
- want an opd entry. */
- if (!info->shared && dyn_h->want_opd)
- continue;
- break;
- }
+ /* Allocate one iff we are building a shared library, the relocation
+ isn't a R_PARISC_FPTR64, or we don't want an opd entry. */
+ if (!info->shared && rent->type == R_PARISC_FPTR64 && dyn_h->want_opd)
+ continue;
/* Create a dynamic relocation for this entry.
More information about the Binutils
mailing list