* [patch] Nios II build_id fix
@ 2014-04-04 17:52 Cesar Philippidis
2014-04-05 1:32 ` Alan Modra
0 siblings, 1 reply; 6+ messages in thread
From: Cesar Philippidis @ 2014-04-04 17:52 UTC (permalink / raw)
To: binutils, Sandra Loosemore
[-- Attachment #1: Type: text/plain, Size: 702 bytes --]
LD isn't able to insert the build_id hash into the .note.gnu.build-id
section because write_build_id () relies on asection.size, which is set
to zero inside nios2_elf32_build_stubs () when that function allocates
memory for linker stubs. The fix is to have nios2_elf32_build_stubs ()
ignore non-stub sections, as done for the ARM targets. Other targets,
AVR specifically, may have a similar problem. However, I don't have
access to those targets, so I'm unable to test a patch for them.
This error manifests itself in gdb.base/sepdebug.exp, so it shouldn't
require a new test case. I've tested it on a nios2-elf target. Is it OK?
If so, please commit since I don't have an SVN account.
Thanks,
Cesar
[-- Attachment #2: binutils_build-id.diff --]
[-- Type: text/plain, Size: 707 bytes --]
2014-04-04 Cesar Philippidis <cesar@codesourcery.com>
* bfd/elf32-nios2.c (nios2_elf32_build_stubs): Ignore non-stub
sections when allocating memory for the linker stubs.
Index: bfd/elf32-nios2.c
===================================================================
--- bfd/elf32-nios2.c (revision 430086)
+++ bfd/elf32-nios2.c (working copy)
@@ -2016,6 +2016,10 @@ nios2_elf32_build_stubs (struct bfd_link
{
bfd_size_type size;
+ /* Ignore non-stub sections. */
+ if (!strstr (stub_sec->name, STUB_SUFFIX))
+ continue;
+
/* Allocate memory to hold the linker stubs. */
size = stub_sec->size;
stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Nios II build_id fix
2014-04-04 17:52 [patch] Nios II build_id fix Cesar Philippidis
@ 2014-04-05 1:32 ` Alan Modra
2014-04-06 3:16 ` Sandra Loosemore
0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2014-04-05 1:32 UTC (permalink / raw)
To: Cesar Philippidis; +Cc: binutils, Sandra Loosemore
On Fri, Apr 04, 2014 at 10:52:22AM -0700, Cesar Philippidis wrote:
> @@ -2016,6 +2016,10 @@ nios2_elf32_build_stubs (struct bfd_link
> {
> bfd_size_type size;
>
> + /* Ignore non-stub sections. */
> + if (!strstr (stub_sec->name, STUB_SUFFIX))
> + continue;
Um, how do you manage to get non-stub sections in the stub bfd? Hmm,
via dynobj being set to the stub bfd, I expect. If so, you could
probably test (stub_sec->flags & SEC_LINKER_CREATED) == 0 instead.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Nios II build_id fix
2014-04-05 1:32 ` Alan Modra
@ 2014-04-06 3:16 ` Sandra Loosemore
2014-04-06 5:12 ` Alan Modra
0 siblings, 1 reply; 6+ messages in thread
From: Sandra Loosemore @ 2014-04-06 3:16 UTC (permalink / raw)
To: Cesar Philippidis, binutils, Alan Modra
On 04/04/2014 07:31 PM, Alan Modra wrote:
> On Fri, Apr 04, 2014 at 10:52:22AM -0700, Cesar Philippidis wrote:
>> @@ -2016,6 +2016,10 @@ nios2_elf32_build_stubs (struct bfd_link
>> {
>> bfd_size_type size;
>>
>> + /* Ignore non-stub sections. */
>> + if (!strstr (stub_sec->name, STUB_SUFFIX))
>> + continue;
>
> Um, how do you manage to get non-stub sections in the stub bfd? Hmm,
> via dynobj being set to the stub bfd, I expect. If so, you could
> probably test (stub_sec->flags & SEC_LINKER_CREATED) == 0 instead.
I had the same question when looking at this code. I think this also
suffers from the same bug (PR 13049) mentioned in the comment on
STUB_SUFFIX in elf32-arm.c.
Hmmmm. I see that stub sections are being created without
SEC_LINKER_CREATED (ld/emultempl/nios2elf.em), while dynamic sections
created in dynobj do have that flag by default (from
ELF_DYNAMIC_SEC_FLAGS). Other sections that end up in dynobj maybe do,
maybe don't -- it doesn't seem like a reliable way to distinguish stub
sections from anything else, at least.
Maybe we could define a new section flag for actual stub sections?
That's a target-independent change (bfd/section.c) and I couldn't
approve it. Alan, WDYT?
Otherwise, I suppose we're stuck with the same band-aid in the ARM
backend....
-Sandra
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Nios II build_id fix
2014-04-06 3:16 ` Sandra Loosemore
@ 2014-04-06 5:12 ` Alan Modra
2014-04-09 0:16 ` Cesar Philippidis
0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2014-04-06 5:12 UTC (permalink / raw)
To: Sandra Loosemore; +Cc: Cesar Philippidis, binutils
On Sat, Apr 05, 2014 at 09:16:10PM -0600, Sandra Loosemore wrote:
> On 04/04/2014 07:31 PM, Alan Modra wrote:
> >On Fri, Apr 04, 2014 at 10:52:22AM -0700, Cesar Philippidis wrote:
> >>@@ -2016,6 +2016,10 @@ nios2_elf32_build_stubs (struct bfd_link
> >> {
> >> bfd_size_type size;
> >>
> >>+ /* Ignore non-stub sections. */
> >>+ if (!strstr (stub_sec->name, STUB_SUFFIX))
> >>+ continue;
> >
> >Um, how do you manage to get non-stub sections in the stub bfd? Hmm,
> >via dynobj being set to the stub bfd, I expect. If so, you could
> >probably test (stub_sec->flags & SEC_LINKER_CREATED) == 0 instead.
>
> I had the same question when looking at this code. I think this
> also suffers from the same bug (PR 13049) mentioned in the comment
> on STUB_SUFFIX in elf32-arm.c.
>
> Hmmmm. I see that stub sections are being created without
> SEC_LINKER_CREATED (ld/emultempl/nios2elf.em), while dynamic
> sections created in dynobj do have that flag by default (from
> ELF_DYNAMIC_SEC_FLAGS). Other sections that end up in dynobj maybe
> do, maybe don't
What other sections? I don't think there will be any. You'll either
have stub sections or dynobj sections. The latter all have
SEC_LINKER_CREATED, the former doesn't.
I handle exactly the same situation in elf64-ppc.c, where dynobj is
forced to be the stub bfd, without resorting to testing for
STUB_SUFFIX in the name.
Note that elf32-arm.c only needs to test for the stub name because the
ARM backend does create other sections (glue, veneer) in the stub bfd
besides stub sections. nios2 doesn't, as far as I can see.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Nios II build_id fix
2014-04-06 5:12 ` Alan Modra
@ 2014-04-09 0:16 ` Cesar Philippidis
2014-04-11 0:18 ` Sandra Loosemore
0 siblings, 1 reply; 6+ messages in thread
From: Cesar Philippidis @ 2014-04-09 0:16 UTC (permalink / raw)
To: Sandra Loosemore, binutils, amodra
[-- Attachment #1: Type: text/plain, Size: 1817 bytes --]
On 4/5/14, 10:12 PM, Alan Modra wrote:
> On Sat, Apr 05, 2014 at 09:16:10PM -0600, Sandra Loosemore wrote:
>> On 04/04/2014 07:31 PM, Alan Modra wrote:
>>> On Fri, Apr 04, 2014 at 10:52:22AM -0700, Cesar Philippidis wrote:
>>>> @@ -2016,6 +2016,10 @@ nios2_elf32_build_stubs (struct bfd_link
>>>> {
>>>> bfd_size_type size;
>>>>
>>>> + /* Ignore non-stub sections. */
>>>> + if (!strstr (stub_sec->name, STUB_SUFFIX))
>>>> + continue;
>>>
>>> Um, how do you manage to get non-stub sections in the stub bfd? Hmm,
>>> via dynobj being set to the stub bfd, I expect. If so, you could
>>> probably test (stub_sec->flags & SEC_LINKER_CREATED) == 0 instead.
>>
>> I had the same question when looking at this code. I think this
>> also suffers from the same bug (PR 13049) mentioned in the comment
>> on STUB_SUFFIX in elf32-arm.c.
>>
>> Hmmmm. I see that stub sections are being created without
>> SEC_LINKER_CREATED (ld/emultempl/nios2elf.em), while dynamic
>> sections created in dynobj do have that flag by default (from
>> ELF_DYNAMIC_SEC_FLAGS). Other sections that end up in dynobj maybe
>> do, maybe don't
>
> What other sections? I don't think there will be any. You'll either
> have stub sections or dynobj sections. The latter all have
> SEC_LINKER_CREATED, the former doesn't.
>
> I handle exactly the same situation in elf64-ppc.c, where dynobj is
> forced to be the stub bfd, without resorting to testing for
> STUB_SUFFIX in the name.
>
> Note that elf32-arm.c only needs to test for the stub name because the
> ARM backend does create other sections (glue, veneer) in the stub bfd
> besides stub sections. nios2 doesn't, as far as I can see.
Checking for dynobjs seemed to work out. I've tested this patch on both
ELF and Linux Nios II targets. Is it OK?
Thanks,
Cesar
[-- Attachment #2: binutils_build-id_stubs.diff --]
[-- Type: text/plain, Size: 1264 bytes --]
2014-04-08 Cesar Philippidis <cesar@codesourcery.com>
bfd/
* elf32-nios2.c (nios2_elf32_build_stubs): Ignore dynobjs
when building function stubs.
Index: bfd/elf32-nios2.c
===================================================================
--- bfd/elf32-nios2.c (revision 430290)
+++ bfd/elf32-nios2.c (working copy)
@@ -2013,16 +2013,18 @@ nios2_elf32_build_stubs (struct bfd_link
for (stub_sec = htab->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
- {
- bfd_size_type size;
-
- /* Allocate memory to hold the linker stubs. */
- size = stub_sec->size;
- stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
- if (stub_sec->contents == NULL && size != 0)
- return FALSE;
- stub_sec->size = 0;
- }
+ /* A dynobj may be forced to be a stub bfd, so ignore it here. */
+ if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
+ {
+ bfd_size_type size;
+
+ /* Allocate memory to hold the linker stubs. */
+ size = stub_sec->size;
+ stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
+ if (stub_sec->contents == NULL && size != 0)
+ return FALSE;
+ stub_sec->size = 0;
+ }
/* Build the stubs as directed by the stub hash table. */
table = &htab->bstab;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Nios II build_id fix
2014-04-09 0:16 ` Cesar Philippidis
@ 2014-04-11 0:18 ` Sandra Loosemore
0 siblings, 0 replies; 6+ messages in thread
From: Sandra Loosemore @ 2014-04-11 0:18 UTC (permalink / raw)
To: Cesar Philippidis; +Cc: binutils, amodra
[-- Attachment #1: Type: text/plain, Size: 278 bytes --]
On 04/08/2014 06:15 PM, Cesar Philippidis wrote:
>
> Checking for dynobjs seemed to work out. I've tested this patch on both
> ELF and Linux Nios II targets. Is it OK?
Thanks. I've checked in this version, with expanded comments to better
explain what is going on.
-Sandra
[-- Attachment #2: binutils-buildid.log --]
[-- Type: text/x-log, Size: 153 bytes --]
2014-04-10 Cesar Philippidis <cesar@codesourcery.com>
bfd/
* elf32-nios2.c (nios2_elf32_build_stubs): Ignore dynobjs
when building function stubs.
[-- Attachment #3: binutils-buildid.patch --]
[-- Type: text/x-patch, Size: 1269 bytes --]
diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c
index 3a44f1d..678f2e3 100644
--- a/bfd/elf32-nios2.c
+++ b/bfd/elf32-nios2.c
@@ -2013,16 +2013,21 @@ nios2_elf32_build_stubs (struct bfd_link_info *info)
for (stub_sec = htab->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
- {
- bfd_size_type size;
-
- /* Allocate memory to hold the linker stubs. */
- size = stub_sec->size;
- stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
- if (stub_sec->contents == NULL && size != 0)
- return FALSE;
- stub_sec->size = 0;
- }
+ /* The stub_bfd may contain non-stub sections if it is also the
+ dynobj. Any such non-stub sections are created with the
+ SEC_LINKER_CREATED flag set, while stub sections do not
+ have that flag. Ignore any non-stub sections here. */
+ if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
+ {
+ bfd_size_type size;
+
+ /* Allocate memory to hold the linker stubs. */
+ size = stub_sec->size;
+ stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
+ if (stub_sec->contents == NULL && size != 0)
+ return FALSE;
+ stub_sec->size = 0;
+ }
/* Build the stubs as directed by the stub hash table. */
table = &htab->bstab;
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-04-11 0:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-04 17:52 [patch] Nios II build_id fix Cesar Philippidis
2014-04-05 1:32 ` Alan Modra
2014-04-06 3:16 ` Sandra Loosemore
2014-04-06 5:12 ` Alan Modra
2014-04-09 0:16 ` Cesar Philippidis
2014-04-11 0:18 ` Sandra Loosemore
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).