This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Handle S_ZEROFILL sections in Mach-O files correctly.
- From: jesse michael <jmichael at suse dot de>
- To: binutils at sourceware dot org
- Date: Thu, 23 Aug 2007 08:45:46 -0700
- Subject: PATCH: Handle S_ZEROFILL sections in Mach-O files correctly.
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.
--- 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)