* [PATCH/RFA] elf64-alpha: Don't put DT_PLTGOT dynamic if no PLT
@ 2002-07-18 14:16 Jason R Thorpe
2002-07-19 7:01 ` Alan Modra
0 siblings, 1 reply; 4+ messages in thread
From: Jason R Thorpe @ 2002-07-18 14:16 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]
The following was found/fixed in NetBSD's 2.11.2-based binutils
by Charles Hannum. The problem is still present in binutils CVS.
The problem occurs when a shared object contains no external references,
and thus has no PLT. elf64_alpha_size_dynamic_sections() inserts a
DT_PLTGOT entry anyway, which confuses the dynamic linker, resulting in
a crash. Here is a test case:
--- a.c ---
fred () { }
---
--- b.c ---
#include <stdio.h>
#include <dlfcn.h>
extern int fred();
main()
{
void *handle;
void *symbol;
handle = dlopen("./a.so", RTLD_NOW);
if (handle == NULL) {
printf("dlopen failed");
exit(1);
}
dlclose(handle);
exit(0);
}
---
% /usr/local/gnu/bin/gcc -shared -o a.so a.c
% /usr/local/gnu/bin/gcc -o b b.c
% ./b
pid 1969 (b): unaligned access: va=0x16001447c pc=0x1600144dc ra=0x160026a68 sp=0x1fffff368 op=ldq
Memory fault (core dumped)
%
(FWIW, the test case was essentially extracted from autoconf tests performed
by perl and zsh.)
The following patch fixes the problem by only adding DT_PLTGOT if there
is a PLT.
OK for mainline?
OK for 2.13 branch?
OK for 2.12 branch?
* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Only insert
DT_PLTGOT into the dynamic section if there is a PLT.
--
-- Jason R. Thorpe <thorpej@wasabisystems.com>
[-- Attachment #2: alpha-patch --]
[-- Type: text/plain, Size: 885 bytes --]
Index: elf64-alpha.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-alpha.c,v
retrieving revision 1.77
diff -c -r1.77 elf64-alpha.c
*** elf64-alpha.c 7 Jul 2002 09:10:40 -0000 1.77
--- elf64-alpha.c 18 Jul 2002 20:49:40 -0000
***************
*** 4120,4131 ****
return false;
}
- if (!add_dynamic_entry (DT_PLTGOT, 0))
- return false;
-
if (relplt)
{
! if (!add_dynamic_entry (DT_PLTRELSZ, 0)
|| !add_dynamic_entry (DT_PLTREL, DT_RELA)
|| !add_dynamic_entry (DT_JMPREL, 0))
return false;
--- 4120,4129 ----
return false;
}
if (relplt)
{
! if (!add_dynamic_entry (DT_PLTGOT, 0)
! || !add_dynamic_entry (DT_PLTRELSZ, 0)
|| !add_dynamic_entry (DT_PLTREL, DT_RELA)
|| !add_dynamic_entry (DT_JMPREL, 0))
return false;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH/RFA] elf64-alpha: Don't put DT_PLTGOT dynamic if no PLT
2002-07-18 14:16 [PATCH/RFA] elf64-alpha: Don't put DT_PLTGOT dynamic if no PLT Jason R Thorpe
@ 2002-07-19 7:01 ` Alan Modra
2002-07-19 9:42 ` Jason R Thorpe
0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2002-07-19 7:01 UTC (permalink / raw)
To: Jason R Thorpe, binutils
On Thu, Jul 18, 2002 at 01:57:11PM -0700, Jason R Thorpe wrote:
> The problem occurs when a shared object contains no external references,
> and thus has no PLT. elf64_alpha_size_dynamic_sections() inserts a
> DT_PLTGOT entry anyway, which confuses the dynamic linker, resulting in
> a crash.
So, it's really a NetBSD dynamic linker bug?
> * elf64-alpha.c (elf64_alpha_size_dynamic_sections): Only insert
> DT_PLTGOT into the dynamic section if there is a PLT.
I'm fairly certain this won't cause any problem with glibc based
systems, so the patch is OK everywhere. Give Richard Henderson
a day or two to nak it before committing though. Hey Richard,
why aren't you listed as binutils alpha maintainer?
--
Alan Modra
IBM OzLabs - Linux Technology Centre
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH/RFA] elf64-alpha: Don't put DT_PLTGOT dynamic if no PLT
2002-07-19 7:01 ` Alan Modra
@ 2002-07-19 9:42 ` Jason R Thorpe
2002-07-19 9:51 ` Richard Henderson
0 siblings, 1 reply; 4+ messages in thread
From: Jason R Thorpe @ 2002-07-19 9:42 UTC (permalink / raw)
To: binutils
On Fri, Jul 19, 2002 at 08:16:59PM +0930, Alan Modra wrote:
> On Thu, Jul 18, 2002 at 01:57:11PM -0700, Jason R Thorpe wrote:
> > The problem occurs when a shared object contains no external references,
> > and thus has no PLT. elf64_alpha_size_dynamic_sections() inserts a
> > DT_PLTGOT entry anyway, which confuses the dynamic linker, resulting in
> > a crash.
>
> So, it's really a NetBSD dynamic linker bug?
It seems more like a BFD bug, to me; it told the dynamic linker there
was a PLT when in fact there was not. How is this not a BFD bug?
A quick random sampling of a few other ELF back-ends shows that they
also do not add DT_PLTGOT if a PLT is not present... alpha was the
odd man out.
> > * elf64-alpha.c (elf64_alpha_size_dynamic_sections): Only insert
> > DT_PLTGOT into the dynamic section if there is a PLT.
>
> I'm fairly certain this won't cause any problem with glibc based
> systems, so the patch is OK everywhere. Give Richard Henderson
> a day or two to nak it before committing though. Hey Richard,
> why aren't you listed as binutils alpha maintainer?
Yah, I was hoping (expecting? :-) Richard would confirm this wouldn't be
a problem for Linux systems...
Once I hear an OK from Richard, it might be a couple of days before
I check it in, though, as I'm leaving for a short vacation tomorrow.
--
-- Jason R. Thorpe <thorpej@wasabisystems.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH/RFA] elf64-alpha: Don't put DT_PLTGOT dynamic if no PLT
2002-07-19 9:42 ` Jason R Thorpe
@ 2002-07-19 9:51 ` Richard Henderson
0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2002-07-19 9:51 UTC (permalink / raw)
To: Jason R Thorpe, binutils
On Fri, Jul 19, 2002 at 09:06:26AM -0700, Jason R Thorpe wrote:
> > So, it's really a NetBSD dynamic linker bug?
>
> It seems more like a BFD bug, to me; it told the dynamic linker there
> was a PLT when in fact there was not. How is this not a BFD bug?
*shrug* It told the dynamic linker the address of the zero
sized PLT section. You still want to fix the dynamic linker.
The change won't hurt anything though.
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-07-19 16:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-18 14:16 [PATCH/RFA] elf64-alpha: Don't put DT_PLTGOT dynamic if no PLT Jason R Thorpe
2002-07-19 7:01 ` Alan Modra
2002-07-19 9:42 ` Jason R Thorpe
2002-07-19 9:51 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).