diff mbox series

[GCC/testsuite] Improve fstack_protector effective target

Message ID df7340ba-907c-1352-46d6-f67b0f86c9fb@foss.arm.com
State New
Headers show
Series [GCC/testsuite] Improve fstack_protector effective target | expand

Commit Message

Thomas Preudhomme Nov. 30, 2017, 4:40 p.m. UTC
Hi,

Effective target fstack_protector fails to return an error for
newlib-based target (such as arm-none-eabi targets) which does not
support stack protector. This is due to the test being too simplist for
stack protection code to be generated by GCC: it does not contain a
local buffer and does not read unknown input.

This commit adds a small local buffer with a copy of the filename to
trigger stack protector code to be generated. The filename is used
instead of the full path so as to ensure the size will fit in the local
buffer.

ChangeLog entry is as follows:

*** gcc/testsuite/ChangeLog ***

2017-11-28  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* lib/target-supports.exp (check_effective_target_fstack_protector):
	Copy filename in local buffer to trigger stack protection.

Testing: Ran gcc.dg/pr38616 on arm-none-eabi and arm-linux-gnueabihf,
the former is now UNSUPPORTED while the latter continues to PASS.

Is this ok for stage3?

Best regards,

Thomas

Comments

Jeff Law Dec. 7, 2017, 9:08 p.m. UTC | #1
On 11/30/2017 09:40 AM, Thomas Preudhomme wrote:
> Hi,
> 
> Effective target fstack_protector fails to return an error for
> newlib-based target (such as arm-none-eabi targets) which does not
> support stack protector. This is due to the test being too simplist for
> stack protection code to be generated by GCC: it does not contain a
> local buffer and does not read unknown input.
> 
> This commit adds a small local buffer with a copy of the filename to
> trigger stack protector code to be generated. The filename is used
> instead of the full path so as to ensure the size will fit in the local
> buffer.
> 
> ChangeLog entry is as follows:
> 
> *** gcc/testsuite/ChangeLog ***
> 
> 2017-11-28  Thomas Preud'homme  <thomas.preudhomme@arm.com>
> 
>     * lib/target-supports.exp (check_effective_target_fstack_protector):
>     Copy filename in local buffer to trigger stack protection.
> 
> Testing: Ran gcc.dg/pr38616 on arm-none-eabi and arm-linux-gnueabihf,
> the former is now UNSUPPORTED while the latter continues to PASS.
> 
> Is this ok for stage3?
OK.
jeff
diff mbox series

Patch

diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index d30fd368922713d3695f22710197ce7094c977cd..8aff16a25823ec48e76ad6ad8fdc8db998a45877 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -1064,7 +1064,11 @@  proc check_effective_target_static {} {
 # Return 1 if the target supports -fstack-protector
 proc check_effective_target_fstack_protector {} {
     return [check_runtime fstack_protector {
-	int main (void) { return 0; }
+	#include <string.h>
+	int main (int argc, char *argv[]) {
+	  char buf[64];
+	  return !strcpy (buf, strrchr (argv[0], '/'));
+	}
     } "-fstack-protector"]
 }