This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: coff section flags: STYP_COPY, in particular, for TI COFF files


John E Hein wrote at 10:54 -0600 on Apr  7:
 > I have asked TI support for a more detailed explanation regarding how
 > their tools behave for various section types.  We'll see what they
 > have to say.

TI has confirmed that "loaded" (when describing the STYP_* flags)
means that raw data appears in their COFF file for that section.  I
assume such sections would never have a section size of 0.

And "allocated" means space set aside when the program is inserted in
memory for running.

BTW, the "allocated" term agrees with the O'Reilly COFF book definitions.
Specifically:

"Allocation deals with the application's memory space.  If a section
is allocated, that means it uses a part of the memory space available
to the application; no other section can occupy this memory space.
The linker output map shows the memory space occupied by the section."


The O'Reilly book has this to say about "loaded":

"Section type information is also used by the system loader.
Depending on the section type, its raw data are either loaded into
memory or not loaded."


Thus, in most cases a section that is loaded would normally be
allocated as well.



So, back to my original problem:

The STYP_COPY section is not allocated, but is loaded.

TI says that this means data appears in the file but is not written to
memory by the system loader:

"The copy section is present in the output COFF file, but doesn't
occupy space in target memory. It can still reference variables in
other sections, etc."

GNU binutils says the same words, but since "loaded" there means that
it is written to memory, the loader is also to write it to memory.
I'm not sure how the system loader is supposed to handle it.  I guess
it writes to memory without allocating (i.e., without reserving that
hunk of memory for that application).  I imagine that there is limited
application for this in a typical unix userland application.

Note that this is different than an overlay (STYP_OVER) which is
relocated, but not allocated nor loaded to memory.
 

In either case, I now think my original patch to coffcode.h is still
valid.  GNU binutils doesn't handle STYP_COPY nor STYP_DSECT at all,
and it looks like STYP_PAD is handled incorrectly.

 - For STYP_COPY & STYP_DSECT flags the patch clears the SEC_ALLOC
   bit.  These STYP_* flags were previously unhandled.

 - Also it fixes how STYP_PAD is treated... namely, it sets SEC_LOAD
   (instead of setting sec_flags to 0 improperly, IMO) unless
   SEC_NEVER_LOAD was set.

 - It's possible that for TI specific COFF handling, we can add
   code to clear SEC_LOAD for STYP_COPY as well.  But my patch
   for the general coffcode.h does not include that.

For reference, here are the comments from include/coff/internal.h
associated with the affected flags:

#define STYP_DSECT       (0x0001)       /* "dummy":  relocated only*/
#define STYP_PAD         (0x0008)       /* "padding": not allocated, not relocated, loaded */
#define STYP_COPY        (0x0010)       /* "copy": for decision function used by field update;
                                           not allocated, not relocated, loaded;
                                           reloc & lineno entries processed normally */

Again, here is the patch.  Further comments?

from  John Hein  <jhein at timing dot com>

	* bfd/coffcode.h [!COFF_WITH_PE] (styp_to_sec_flags): handle
	STYP_COPY & STYP_DSECT flags. Fix STYP_PAD to set SEC_LOAD as
	appropriate. These changes match comments in
	include/coff/internal.h

--- bfd/coffcode.h.orig	Fri Apr  4 17:41:35 2003
+++ bfd/coffcode.h	Fri Apr  4 17:43:41 2003
@@ -644,8 +644,10 @@
       sec_flags |= SEC_DEBUGGING;
 #endif
     }
+  else if ((styp_flags & STYP_PAD) && (sec_flags & SEC_NEVER_LOAD))
+	sec_flags = 0;
   else if (styp_flags & STYP_PAD)
-    sec_flags = 0;
+	sec_flags = SEC_LOAD;
   else if (strcmp (name, _TEXT) == 0)
     {
       if (sec_flags & SEC_NEVER_LOAD)
@@ -702,6 +704,9 @@
   if (styp_flags & STYP_OTHER_LOAD)
     sec_flags = (SEC_LOAD | SEC_ALLOC);
 #endif /* STYP_SDATA */
+
+  if (styp_flags & (STYP_COPY | STYP_DSECT))
+	sec_flags &= ~SEC_ALLOC);
 
 #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
   /* As a GNU extension, if the name begins with .gnu.linkonce, we


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]