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: Sat, 17 Jan 2004 08:30:16 +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,
> >
> > 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.
>
> Yeah that is a good idea. I like the patch too.
>
> > 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.
>
> OK, please do that as well.
>
Hi,
Here is a slightly revised version of the patch. I can see no reason to
do all the bfd_set_file_flags() error checking (for each data symbol import)
when setting a known flag on a bfd of known format, so I just set the flag
directly with 'output_bfd->flags &= ~WP_TEXT'
I've also have added notes to ld.texinfo.
Danny
bfd/ChangeLog
2003-01-16 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-16 Danny Smith <dannysmith@users.sourceforge.net>
* pe-dll.c (pe_create_import_fixup): Unset WP_TEXT.
* ld.texinfo (--omagic): Note that writable text section
does not conform to published PE-COFF specs.
(--enable-auto-import): Likewise.
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 16 Jan 2004 21:23:41 -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 16 Jan 2004 21:23:45 -0000
*************** pe_create_import_fixup (arelent *rel, as
*** 2176,2181 ****
--- 2176,2182 ----
/* If we ever use autoimport, we have to cast text section writable. */
config.text_read_only = FALSE;
+ output_bfd->flags &= ~WP_TEXT;
}
if (addend == 0 || link_info.pei386_runtime_pseudo_reloc)
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.103
diff -c -3 -p -r1.103 ld.texinfo
*** ld/ld.texinfo 13 Jan 2004 11:10:53 -0000 1.103
--- ld/ld.texinfo 16 Jan 2004 21:24:02 -0000
*************** Turn off page alignment of sections, and
*** 687,693 ****
Set the text and data sections to be readable and writable. Also, do
not page-align the data segment, and disable linking against shared
libraries. If the output format supports Unix style magic numbers,
! mark the output as @code{OMAGIC}.
@kindex --no-omagic
@cindex OMAGIC
--- 687,695 ----
Set the text and data sections to be readable and writable. Also, do
not page-align the data segment, and disable linking against shared
libraries. If the output format supports Unix style magic numbers,
! mark the output as @code{OMAGIC}. Note: Although a writable text section
! is allowed for PE-COFF targets, it does not conform to the format
! specification published by Microsoft.
@kindex --no-omagic
@cindex OMAGIC
*************** uwin, pw, etc. For instance, cygwin DLL
*** 1950,1957 ****
@item --enable-auto-import
Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
DATA imports from DLLs, and create the necessary thunking symbols when
! building the import libraries with those DATA exports. This generally
! will 'just work' -- but sometimes you may see this message:
"variable '<var>' can't be auto-imported. Please read the
documentation for ld's @code{--enable-auto-import} for details."
--- 1952,1964 ----
@item --enable-auto-import
Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
DATA imports from DLLs, and create the necessary thunking symbols when
! building the import libraries with those DATA exports. Note: Use of the
! 'auto-import' extension will cause the text section of the image file
! to be made writable. This is does not conform to the PE-COFF format
! specification published by Microsoft.
!
! Using 'auto-import' generally will 'just work' -- but sometimes you may
! see this message:
"variable '<var>' can't be auto-imported. Please read the
documentation for ld's @code{--enable-auto-import} for details."
http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.