[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: objcopy --add-section doubt
From: |
Nick Clifton |
Subject: |
Re: objcopy --add-section doubt |
Date: |
Mon, 30 Jan 2006 13:13:32 +0000 |
User-agent: |
Thunderbird 1.5 (X11/20051201) |
Hi Kartikeyan,
Thanks for the test case. Using it I was able to reproduce the problem.
so NULL is being returned as newsect->name is not NULL
Yes - this is the heart of the matter. What is happening is that you
are attempting to add a section that already exists. The old (RH9)
binutils silently allowed this, which was incorrect. The current
binutils sources does not allow the existing section to be re-added, but
it does produce a very unhelpful warning message.
The attached patch (which I will be checking into the sources shortly)
changes the warning to:
can't add section '.skdata' - it already exists!
which I think is much better.
I AM NOT A EXPERT IN BINUTILS.
It's OK there is no need to shout.
If you want to achieve the old behaviour of RH9 then you can just amend
your objcopy command line to include "--remove-section .skdata" before
the "--add-section .skdata=a" switch.
Cheers
Nick
binutils/ChangeLog
2006-01-30 Nick Clifton <address@hidden>
* objcopy.c (copy_object): Catch the case where an attempt is made
to add a section that already exists and produce a more helpful
warning message.
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.93
diff -c -3 -p -r1.93 objcopy.c
*** binutils/objcopy.c 18 Jan 2006 11:01:09 -0000 1.93
--- binutils/objcopy.c 30 Jan 2006 12:58:45 -0000
*************** copy_object (bfd *ibfd, bfd *obfd)
*** 1313,1325 ****
if (pset != NULL && pset->set_flags)
flags = pset->flags | SEC_HAS_CONTENTS;
! padd->section = bfd_make_section_with_flags (obfd, padd->name, flags);
! if (padd->section == NULL)
{
! non_fatal (_("can't create section `%s': %s"),
! padd->name, bfd_errmsg (bfd_get_error ()));
return FALSE;
}
if (! bfd_set_section_size (obfd, padd->section, padd->size))
{
--- 1313,1335 ----
if (pset != NULL && pset->set_flags)
flags = pset->flags | SEC_HAS_CONTENTS;
! /* bfd_make_section_with_flags() does not return very helpful
! error codes, so check for the most likely user error first. */
! if (bfd_get_section_by_name (obfd, padd->name))
{
! non_fatal (_("can't add section '%s' - it already exists!"),
padd->name);
return FALSE;
}
+ else
+ {
+ padd->section = bfd_make_section_with_flags (obfd, padd->name,
flags);
+ if (padd->section == NULL)
+ {
+ non_fatal (_("can't create section `%s': %s"),
+ padd->name, bfd_errmsg (bfd_get_error ()));
+ return FALSE;
+ }
+ }
if (! bfd_set_section_size (obfd, padd->section, padd->size))
{