public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Mark E." <snowball3@bigfoot.com>
To: binutils@sourceware.cygnus.com
Subject: patch for COFF .section
Date: Tue, 27 Jun 2000 12:54:00 -0000	[thread overview]
Message-ID: <3958CE32.27503.12021EF@localhost> (raw)

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 ();

             reply	other threads:[~2000-06-27 12:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-06-27 12:54 Mark E. [this message]
2000-06-29 16:54 Nick Clifton
2000-06-29 21:55 Mark E.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3958CE32.27503.12021EF@localhost \
    --to=snowball3@bigfoot.com \
    --cc=binutils@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).