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]

[Ada] Refuse executable with same name as source


Currently it is possible to accidentally and silently overwrite
a source file with an executable, if the sourcefile has no file
extension and the operating system uses no file extensions for
executables. This fixes that.

The following test case should not overwrite hello with an executable,
but instead exit with an error message:

% cat >hello <<EOF && gnatmake hello
> with Text_IO; use Text_IO;
> procedure Hello is
> begin
>    Put_Line ("This source self-destructs after compilation");
> end Hello;
> EOF
gcc -c -x ada hello
hello:2:11: warning: file name does not match unit name, should be "hello.adb"
gnatbind -x hello.ali
gnatlink hello.ali
gnatlink: executable name "hello" matches source file name "hello"
gnatmake: *** link failed.

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-09-10  Geert Bosch  <bosch@adacore.com>

	* gnatlink.adb (Check_ Existing_Executable): New procedure for checking
	validity of executable name and removing any existing executable
	(Gnatlink): Call Check_Existing_Executable.

Attachment: difs
Description: Text document


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