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]

[PATCH] Unshare RTL for __stack_chk_guard


The following patch fixes wrong code bug on m68k and, possibly, other targets when -fstack-protector option is used. Consider the following testcase:

#include <stdlib.h>
#include <string.h>
void doTest1(void) {
  volatile char foo[10];
  memset((void *)foo, 1, 100);
}
void doTest2(void) {
  volatile char foo[10];
  memset((void *)foo, 1, 100);
}

Assembler for both functions should be exactly the same, however, on m68k it is compiled to:

doTest1:
 		link.w %fp,#-16
 		lea __stack_chk_guard,%a0
 		move.l (%a0),-4(%fp)
 		pea 100.w
 		...

doTest2:
 		link.w %fp,#-16
 		move.l (%a0),-4(%fp) // %a0 is not initialized
 		pea 100.w
 		...

The problem is in sharing DECL_RTL of __stack_chk_guard_decl.

Currently, RTL for __stack_chk_guard_decl can be shared across functions. The RTL is "(mem (symbol_ref))" and m68k reloads "(symbol_ref)" into a register to produce a valid memory reference, hence, it becomes "(mem (reg))".

The problem is that the transformations are applied directly to DECL_RTL(stack_chk_guard_decl), so all subsequent functions pick up transformed RTL, which is, in general case, wrong.

The fix is to set RTX_FLAG(used) of DECL_RTL(stack_chk_guard_decl) to "1". This will make transformations create local copies of DECL_RTL and apply changes to that.

Testing on x86_64-linux-gnu is underway.

OK for trunk if testing shows no regressions?

Thanks,

--
Maxim Kuvyrkov
CodeSourcery
maxim@codesourcery.com
(650) 331-3385 x724

Attachment: gcc-stack-guard-fix.ChangeLog
Description: Text document

Attachment: gcc-stack-guard-fix.patch
Description: Text document


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