Merge pseudo-reloc-v2 support from mingw/pseudo-reloc.c

Charles Wilson cygwin@cwilson.fastmail.fm
Tue Oct 6 23:54:00 GMT 2009


As discussed on cygwin-developers...
http://cygwin.com/ml/cygwin-developers/2009-10/msg00052.html
and thread. Please refer to that thread for the justification of this
patch, and some of the details of its evolution.

The changelog entry below is somewhat odd (multiple sections) because of
the licensing differences in the various files. Kai's only contribution
was to the pseudo-reloc.c code, which is entirely public domain (and he
placed his contributions to that file into the public domain, as well).
Similarly, my contributions to pseudo-reloc.c are also public domain.

Bowever, the changes to the other cygwin files are mine and are covered
by assignment to Red Hat.

Hence, three separate "entries". One question: when it comes time to
commit this to CVS, should it be done all in one lump, or 1-2-3 very
quick separate commits (even though the tree would be broken between,
say, #1 and #2)?

2009-10-06  Charles Wilson  <...>

	Additional pseudo-reloc-v2 support
	* ntdll.h: Add custom NTSTATUS value for pseudo-reloc
	errors STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION.
	* pinfo.cc (status_exit): Map custom pseudo-reloc
	error value STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION to 127.
	* sigproc.cc (child_info::proc_retry): Return exit code when
        STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION.

2009-10-06  Charles Wilson  <...>

	Cygwin modifications to pseudo-reloc.c
	* lib/pseudo-reloc.c: Added comments throughout and various
	whitespace fixes. Exploit cygwin_internal(CW_EXIT_PROCESS,...)
	for fatal error handling that is consistent with cygwin process
	life-cycle. Ensure state variable (in _pei386_runtime_relocator)
	is unique to each address space, across fork().
	(__print_reloc_error): New function for reporting errors in a
	manner supported by cygwin at this early stage of the process
	life-cycle.
[*]	(_pei386_runtime_relocator): Ensure relocations performed
	only once for each address space, but are repeated after fork()
	in the new address space.
	(__write_memory) [MINGW]: Ensure that b is always initialized
	by call to VirtualQuery, even if -DNDEBUG.

2009-10-06  Kai Tietz  <...>

	Rewrite (copied from winsup/mingw/pseudo-reloc.c)
	* lib/pseudo-reloc.c: Rewritten to support v2 pseudo-relocs.
	(struct runtime_pseudo_reloc): Renamed to...
	(struct runtime_pseudo_reloc_item_v1): this.
	(struct runtime_pseudo_reloc_item_v2): New typedef.
	(struct runtime_pseudo_reloc_v2): New typedef.
	(__write_memory): New function (no longer need writable .text
	section, nor need to fold .rdata into .data).
	(do_pseudo_reloc): Rewritten entirely, to support both
	v1 and v2 relocations.
	(_pei386_runtime_relocator): Ensure relocations performed
	only once for each address space.


There are three attachments:

1) The full patch (04-pseudo-reloc-v2-support.patch)
2) The diff between winsup/mingw/pseudo-reloc.c and
winsup/cygwin/lib/pseudo-reloc.c -- that is, the diff between
pseudo-commit #1 and pseudo-commit #2.
(04-pseudo-reloc-cygwin-changes.patch)
3) A tarball containing a number of (standalone) test cases
(pseudo-reloc-tests-v3.tar.bz2).

After building and installing the new DLL (and libcygwin.a), the test
cases should be fairly explanatory. There are individual READMEs and
expected output is documented. To build, simply do 'make' in the
appropriate subdirectory.  You will need binutils-2.19.51-1 (or CVS
binutils newer than 2008-11-24) to test the v2 relocation, but the v1
tests will work with any cygwin binutils newer than 2003.

BTW: applications compiled to use v2 relocs will still work if you
execute those apps under an older cygwin DLL -- *unless* an error
condition occurs and the cygwin_internal(CW_EXIT_PROCESS, ...) is
triggered. Older cygwins don't support that particular cygwin_internal flag.

[*] by using NO_COPY on the was_init state variable in
_pei386_runtime_relocator, we ensure that the relocation is repeated in
the forkee. However, if at some point ld is changed so that .text (and
.rdata) are marked non-writable (unlike now, where .text is explicitly
writable and .rdata is folded in to the writable .data section), it's
not clear to me what effect that might have on the cygwin's (and
win32's) behavior when setting up the forkee's memory contents.

But...we can cross that bridge when we come to it. It may be that
nothing would need to change.

--
Chuck
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 04-pseudo-reloc-v2-support.patch
Type: application/x-patch
Size: 14653 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20091006/a595f473/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 04-pseudo-reloc-cygwin-changes.patch
Type: application/x-patch
Size: 10745 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20091006/a595f473/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pseudo-reloc-tests-v3.tar.bz2
Type: application/octet-stream
Size: 3582 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20091006/a595f473/attachment.obj>


More information about the Cygwin-patches mailing list