This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

improve collect2 to preserve a RO output as the linker does


Hello,

This is a followup on an old issue first discussed at

  http://gcc.gnu.org/ml/gcc-patches/2008-05/msg01290.html

The original problem is still visible today:

<< While some target linkers silently replace read-only output files,
   others report an error in such circumstances. [...]
   collect2 doesn't mimic this behavior and always replaces, which might
   cause suprises to some users.
>>

Discussing the patch proposal, Ian (cc'ed) made the following suggestion:

<< I don't really like having this be target dependent.  I think that
instead you should change collect2 so that it only removes the output
file if it believes that it created the output file.  That is,
introduce some global variable which says whether to delete the output
file, and initialize it to false.  If tlink_execute succeeds, then set
the variable to true, so that the output file is deleted if collect2
fails.  If tlink_execute fails, don't have collect2 delete the output
file; let the invoked linker make the decision in that case.
>>

The attached patch is an implementation of this suggestion that we have
been using in our trees for a couple of years now.

Bootstraps and regtests fine on mainline for x86-linux.

OK ?

Thanks in advance for your feedback,

With Kind Regards,

Olivier


2012-05-03  Olivier Hainque  <hainque@adacore.com>

	* collect2.c (may_unlink_output_file): New global.
	(maybe_unlink): Honor it.
	* collect2.h: Add extern for it.
	* tlink.c (do_tlink): Set it to true if the link succeeded.

Attachment: c2unlink.dif
Description: video/dv


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]