public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: Handle S_ZEROFILL sections in Mach-O files correctly.
@ 2007-08-23 16:39 jesse michael
  2007-08-31 15:20 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: jesse michael @ 2007-08-23 16:39 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1098 bytes --]

The bfd mach-o loading code in both binutils and gdb has a bug with the
handling of S_ZEROFILL sections that results in certain non-S_ZEROFILL
sections being handled improperly.

The code in bfd_mach_o_make_bfd_section() treats BFD_MACH_O_S_ZEROFILL 
as if it were a bit flag when in reality, the section type is an 8-bit
subfield contained within the section->flags value.

There's even a comment earlier in mach-o.c pointing that out, but the
two following defines aren't used.

/* The flags field of a section structure is separated into two parts a section
   type and section attributes.  The section types are mutually exclusive (it
   can only have one type) but the section attributes are not (it may have more
   than one attribute).  */

#define SECTION_TYPE             0x000000ff     /* 256 section types.  */
#define SECTION_ATTRIBUTES       0xffffff00     /*  24 section attributes.  */

Because BFD_MACH_O_S_ZEROFILL is treated as a bit flag, any section types
with an odd value will not properly get the SEC_HAS_CONTENTS, SEC_LOAD, 
and SEC_CODE flags applied to the bfdsec struct.

[-- Attachment #2: binutils-zerofill.diff --]
[-- Type: text/x-patch, Size: 496 bytes --]

--- mach-o.c.orig	2007-08-23 07:57:05.375166000 +0200
+++ mach-o.c	2007-08-23 08:00:07.917125000 +0200
@@ -644,7 +644,7 @@
   sprintf (sname, "%s.%s.%s", prefix, section->segname, section->sectname);
 
   flags = SEC_ALLOC;
-  if (!(section->flags & BFD_MACH_O_S_ZEROFILL))
+  if ((section->flags & SECTION_TYPE) != BFD_MACH_O_S_ZEROFILL)
     flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC | SEC_CODE;
   bfdsec = bfd_make_section_anyway_with_flags (abfd, sname, flags);
   if (bfdsec == NULL)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: Handle S_ZEROFILL sections in Mach-O files correctly.
  2007-08-23 16:39 PATCH: Handle S_ZEROFILL sections in Mach-O files correctly jesse michael
@ 2007-08-31 15:20 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2007-08-31 15:20 UTC (permalink / raw)
  To: jesse michael; +Cc: binutils

Hi Jesse,

> The code in bfd_mach_o_make_bfd_section() treats BFD_MACH_O_S_ZEROFILL 
> as if it were a bit flag when in reality, the section type is an 8-bit
> subfield contained within the section->flags value.

Good catch.  I have checked your patch in along with this ChangeLog entry.

Cheers
   Nick

bfd/ChangeLog
2007-08-31  Jesse Michael  <jmichael@suse.de>

	* mach-o.c (bfd_mach_o_make_bfd_section): Fix test for non
	zerofill sections.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-31 14:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-23 16:39 PATCH: Handle S_ZEROFILL sections in Mach-O files correctly jesse michael
2007-08-31 15:20 ` Nick Clifton

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).