This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [Patch] Fix PE dll -auto-import breakage from enforcing PE specs for section flags
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: binutils <binutils at sources dot redhat dot com>
- Date: Wed, 14 Jan 2004 23:45:20 +1100 (EST)
- Subject: Re: [Patch] Fix PE dll -auto-import breakage from enforcing PE specs for section flags
--- Nick Clifton <nickc@redhat.com> wrote: > Hi Danny,
>
> > The problem is that -auto-import wants object with writeable .text
> > section (see pe_create_import_fixup() in ld/pe-dll.c) but
> > _bfd_XXi_swap_scnhdr_out unsets IMAGE_SCN_MEM_WRITE
> >
Hi,
'--enable-auto-import' isn't the only problem with enforcing a readonly
.text section. ld --omagic also break strict PE section flag specs by
setting IMAGE_SCN_MEM_WRITE flag on .text.
(objcopy --writable-text would also do the same, but it doesn't appear to
apply to PE target).
What about using WP_TEXT file flag (set by default) as a runtime flag?
ld --omagic already unsets this flag. Make --enable-auto-import do the
same when it is actually exercised.
As I post, I realize that ld.texi probably needs to include warnings
that the use of --enable-auto-import or --omagic will break strict PE specs.
I'll add those, once this is sorted.
Danny
bfd/ChangeLog
2003-01-14 Danny Smith <dannysmith@users.sourceforge.net>
* peXXigen.c (_bfd_XXi_swap_scnhdr_out): Don't remove
IMAGE_SCN_MEM_WRITE flag from .text section if WP_TEXT
has been unset.
1d/ChangeLog
2003-01-14 Danny Smith <dannysmith@users.sourceforge.net>
* pe-dll.c (pe_create_import_fixup): Unset WP_TEXT.
Index: bfd/peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.20
diff -c -3 -p -r1.20 peXXigen.c
*** bfd/peXXigen.c 15 Dec 2003 11:50:11 -0000 1.20
--- bfd/peXXigen.c 14 Jan 2004 12:25:07 -0000
*************** _bfd_XXi_swap_scnhdr_out (abfd, in, out)
*** 985,997 ****
pe_required_section_flags * p;
int flags = scnhdr_int->s_flags;
for (p = known_sections; p->section_name; p++)
if (strcmp (scnhdr_int->s_name, p->section_name) == 0)
{
- /* We have defaulted to adding the IMAGE_SCN_MEM_WRITE flag, but now
- we know exactly what this specific section wants so we remove it
- and then allow the must_have field to add it back in if necessary. */
- flags &= ~IMAGE_SCN_MEM_WRITE;
flags |= p->must_have;
break;
}
--- 985,1003 ----
pe_required_section_flags * p;
int flags = scnhdr_int->s_flags;
+ /* We have defaulted to adding the IMAGE_SCN_MEM_WRITE flag, but now
+ we know exactly what this specific section wants so we remove it
+ and then allow the must_have field to add it back in if necessary.
+ However, we don't remove IMAGE_SCN_MEM_WRITE flag from .text if the
+ default WP_TEXT file flag has been unset. */
+
+ if (strcmp (scnhdr_int->s_name, ".text")
+ || (bfd_get_file_flags (abfd) & WP_TEXT))
+ flags &= ~IMAGE_SCN_MEM_WRITE;
+
for (p = known_sections; p->section_name; p++)
if (strcmp (scnhdr_int->s_name, p->section_name) == 0)
{
flags |= p->must_have;
break;
}
Index: ld/pe-dll.c
===================================================================
RCS file: /cvs/src/src/ld/pe-dll.c,v
retrieving revision 1.65
diff -c -3 -p -r1.65 pe-dll.c
*** ld/pe-dll.c 5 Dec 2003 11:30:18 -0000 1.65
--- ld/pe-dll.c 14 Jan 2004 12:30:17 -0000
*************** pe_create_import_fixup (arelent *rel, as
*** 2172,2181 ****
--- 2172,2183 ----
if (!name_thunk_sym || name_thunk_sym->type != bfd_link_hash_defined)
{
bfd *b = make_singleton_name_thunk (name, output_bfd);
+ flagword flags = bfd_get_file_flags (output_bfd);
add_bfd_to_link (b, b->filename, &link_info);
/* If we ever use autoimport, we have to cast text section writable. */
config.text_read_only = FALSE;
+ bfd_set_file_flags (output_bfd, (flags & ~WP_TEXT));
}
if (addend == 0 || link_info.pei386_runtime_pseudo_reloc)
http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.