patch for COFF .section
Mark E.
snowball3@bigfoot.com
Tue Jun 27 12:54:00 GMT 2000
Hello again,
The BFD_ASSEMBLER version of obj_coff_section has some major flaws. If the .section
directive doesn't have a flags argument, the section's attributes are changed to
SEC_LOAD. And if the .section directive does have a flags argument, it always changes
the section's attributes, even if they've already been set. The patch below corrects
this by:
* not changing an existing section's attributes if a flags argument isn't present.
* warn if the new attributes don't match the section's current attributes.
2000-06-27 Mark Elbrecht <snowball3@bigfoot.com>
* config/obj-coff.c (obj_coff_setcion) [BFD_ASSEMBLER]: If the
flags argument is not present, don't change an existing section's
section's attributes. If the flags argument is present, warn if the
attributes don't match the section's current attributes. When
long section names are supported, set SEC_LINK_ONCE and
SEC_LINK_DUPLICATES_DISCARD for a new .gnu.linkonce section.
Index: src/gas/config/obj-coff.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-coff.c,v
retrieving revision 1.25
diff -c -p -r1.25 obj-coff.c
*** obj-coff.c 2000/06/17 22:00:30 1.25
--- obj-coff.c 2000/06/27 19:33:38
*************** obj_coff_section (ignore)
*** 1353,1359 ****
char c;
char *name;
unsigned int exp;
! flagword flags;
asection *sec;
if (flag_mri)
--- 1353,1359 ----
char c;
char *name;
unsigned int exp;
! flagword flags, oldflags;
asection *sec;
if (flag_mri)
*************** obj_coff_section (ignore)
*** 1375,1381 ****
SKIP_WHITESPACE ();
exp = 0;
! flags = SEC_LOAD;
if (*input_line_pointer == ',')
{
--- 1375,1381 ----
SKIP_WHITESPACE ();
exp = 0;
! flags = SEC_NO_FLAGS;
if (*input_line_pointer == ',')
{
*************** obj_coff_section (ignore)
*** 1420,1437 ****
sec = subseg_new (name, (subsegT) exp);
! if (flags != SEC_NO_FLAGS)
{
! flagword oldflags;
- oldflags = bfd_get_section_flags (stdoutput, sec);
- oldflags &= SEC_LINK_ONCE | SEC_LINK_DUPLICATES;
- flags |= oldflags;
-
if (! bfd_set_section_flags (stdoutput, sec, flags))
! as_warn (_("error setting flags for \"%s\": %s"),
! bfd_section_name (stdoutput, sec),
! bfd_errmsg (bfd_get_error ()));
}
demand_empty_rest_of_line ();
--- 1420,1456 ----
sec = subseg_new (name, (subsegT) exp);
! oldflags = bfd_get_section_flags (stdoutput, sec);
! if (oldflags == SEC_NO_FLAGS)
{
! /* Set section flags for a new section just created by subseg_new.
! Provide a default if no flags were parsed. */
! if (flags == SEC_NO_FLAGS)
! flags = SEC_LOAD;
!
! #ifdef COFF_LONG_SECTION_NAMES
! /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
! sections so adjust_reloc_syms in write.c will correctly handle
! relocs which refer to non-local symbols in these sections. */
! if (strncmp (name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0)
! flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
! #endif
if (! bfd_set_section_flags (stdoutput, sec, flags))
! as_warn (_("error setting flags for \"%s\": %s"),
! bfd_section_name (stdoutput, sec),
! bfd_errmsg (bfd_get_error ()));
! }
! else if (flags != SEC_NO_FLAGS)
! {
! /* This section's attributes have already been set. Warn if the
! attributes don't match. */
! flagword matchflags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
! | SEC_DATA | SEC_SHARED;
! if ((flags ^ oldflags) & matchflags)
! {
! as_warn (_("Ignoring changed section attributes for %s"), name);
! }
}
demand_empty_rest_of_line ();
More information about the Binutils
mailing list