Bug 31468 - Calling gcc with empty output filename can remove crt0.o (crt1.o on linux)
Summary: Calling gcc with empty output filename can remove crt0.o (crt1.o on linux)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Martin Liška
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-04 15:41 UTC by Michael Haubenwallner
Modified: 2017-06-22 11:42 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 8.0
Known to fail: 5.4.0, 6.3.0, 7.1.0
Last reconfirmed: 2017-05-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Haubenwallner 2007-04-04 15:41:06 UTC
Try these commands:
$ echo 'int main(void) { return 0;}' > xx.c
$ gcc -o '' xx.c

And if you have permission to remove /path/to/crtX.o, it will be removed,
because gcc uses that as the output file.

Although it is illegal to call gcc with an empty output filename,
it really should not break any further link step by removing that crtX.o.

Have seen this on linux, aix, solaris, and hpux.

The best informational error message is from hpux:
$ gcc -o '' xx.c                                                                                                              
/usr/ccs/bin/ld: Can't create /usr/ccs/lib/crt0.o
/usr/ccs/bin/ld: Permission denied
collect2: ld returned 1 exit status

Same is true for 'g++', have not tried others.
Comment 1 Martin Liška 2017-05-03 10:18:19 UTC
Confirmed, huh, it's very old issue. I've got patch for that.
Comment 2 Martin Liška 2017-05-15 12:49:24 UTC
Author: marxin
Date: Mon May 15 12:48:35 2017
New Revision: 248060

URL: https://gcc.gnu.org/viewcvs?rev=248060&root=gcc&view=rev
Log:
Do not allow empty argument of -o option (PR driver/31468).

2017-05-15  Martin Liska  <mliska@suse.cz>

	PR driver/31468
	* gcc.c (process_command): Do not allow empty argument of -o option.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gcc.c
Comment 3 Martin Liška 2017-05-15 13:28:14 UTC
Fixed on trunk so far.
Comment 4 Martin Liška 2017-06-22 11:19:08 UTC
Author: marxin
Date: Thu Jun 22 11:18:36 2017
New Revision: 249521

URL: https://gcc.gnu.org/viewcvs?rev=249521&root=gcc&view=rev
Log:
Backport r248060

2017-06-22  Martin Liska  <mliska@suse.cz>

	Backport from mainline
	2017-05-15  Martin Liska  <mliska@suse.cz>

	PR driver/31468
	* gcc.c (process_command): Do not allow empty argument of -o option.

Modified:
    branches/gcc-6-branch/gcc/ChangeLog
    branches/gcc-6-branch/gcc/gcc.c
Comment 5 Martin Liška 2017-06-22 11:29:36 UTC
Author: marxin
Date: Thu Jun 22 11:29:02 2017
New Revision: 249534

URL: https://gcc.gnu.org/viewcvs?rev=249534&root=gcc&view=rev
Log:
Backport r248060

2017-06-22  Martin Liska  <mliska@suse.cz>

	Backport from mainline
	2017-05-15  Martin Liska  <mliska@suse.cz>

	PR driver/31468
	* gcc.c (process_command): Do not allow empty argument of -o option.

Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/gcc.c
Comment 6 Martin Liška 2017-06-22 11:39:29 UTC
Author: marxin
Date: Thu Jun 22 11:38:56 2017
New Revision: 249546

URL: https://gcc.gnu.org/viewcvs?rev=249546&root=gcc&view=rev
Log:
Backport r248060

2017-06-22  Martin Liska  <mliska@suse.cz>

	Backport from mainline
	2017-05-15  Martin Liska  <mliska@suse.cz>

	PR driver/31468
	* gcc.c (process_command): Do not allow empty argument of -o option.

Modified:
    branches/gcc-7-branch/gcc/ChangeLog
    branches/gcc-7-branch/gcc/gcc.c
Comment 7 Martin Liška 2017-06-22 11:42:22 UTC
Fixed on all active branches.