Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong emission of st_align(4)_u8 HSAIL insn #4

Closed
marxin opened this issue Mar 14, 2016 · 4 comments
Closed

Wrong emission of st_align(4)_u8 HSAIL insn #4

marxin opened this issue Mar 14, 2016 · 4 comments

Comments

@marxin
Copy link

marxin commented Mar 14, 2016

Running following snippet with GCC HSA BE:
http://pastebin.com/x93CvJDM

Produces:
prog kernel &main__omp_fn_0(kernarg_u64 %_omp_data_i)
{
ld_kernarg_align(8)_u64 $d0, [%_omp_data_i];

@BB_3045_2:
ld_align(8)_u64 $d0, [$d0];
st_align(4)_u8 9, 0, 0, 0, [$d0+8];
ret;
};

While running gccbrig I see following wrong store of zero value (instead of 9):
__wi_loop_x:
d0_28 = MEM[(unsigned long *)__args_27(D)];
_29 = VIEW_CONVERT_EXPR<unsigned char *>(d0_28);
d0_30 = MEM[(unsigned long *)_29];
_31 = d0_30 + 8;
_32 = VIEW_CONVERT_EXPR<unsigned char *>(_31);
*_32 = 0;
__local_x_34 = __local_x_1 + 1;
if (__cur_wg_size_x_11 > __local_x_34)
goto <bb 5> (__wi_loop_x);
else
goto <bb 6>;

Thanks,
Martin

@pjaaskel
Copy link
Collaborator

This is an illegal instruction:

st_align(4)_u8 9, 0, 0, 0, [$d0+8];

st takes only two arguments, this has somehow pushed in 5. HSAILasm can disassemble the BRIG, but cannot assemble it again:

$ HSAILasm -disassemble phsa-temp/program-0.brig 
$ HSAILasm phsa-temp/program-0.hsail

>       st_align(4)_u8  9, 0, 0, 0, [$d0+8];
>                          ^
input(10,20): Invalid operand 1, expected: an address

I wonder how can it work for some other platform. Using the standard struct parsing, I cannot get access to the 9 byte in that list.

@marxin
Copy link
Author

marxin commented Mar 24, 2016

Ok, I will fix that in HSA back-end, however can you please paste here a link to an issue you did for HSAILAsm?

Thanks

@pjaaskel
Copy link
Collaborator

I didn't because I wasn't sure if this is a HSAILasm bug after all. It should complain in case trying to disassemble an illegal BRIG such as this? It complains when it tries to assembly it.

@marxin
Copy link
Author

marxin commented Mar 24, 2016

I think so, because they do it in different situations where an assembled BRIG is invalid.
They will appreciate that, maybe it can catch more cases.

Martin

pjaaskel pushed a commit that referenced this issue Apr 30, 2018
When -fcf-protection -mcet is used, I got

FAIL: g++.dg/eh/sighandle.C

(gdb) bt
 #0  _Unwind_RaiseException (exc=exc@entry=0x416ed0)
    at /export/gnu/import/git/sources/gcc/libgcc/unwind.inc:140
 #1  0x00007ffff7d9936b in __cxxabiv1::__cxa_throw (obj=<optimized out>,
    tinfo=0x403dd0 <typeinfo for int@@CXXABI_1.3>, dest=0x0)
    at /export/gnu/import/git/sources/gcc/libstdc++-v3/libsupc++/eh_throw.cc:90
 #2  0x0000000000401255 in sighandler (signo=11, si=0x7fffffffd6f8,
    uc=0x7fffffffd5c0)
    at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:9
 #3  <signal handler called> <<<< Signal frame which isn't on shadow stack
 #4  dosegv ()
    at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:14
 #5  0x00000000004012e3 in main ()
    at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:30
(gdb) p frames
$6 = 5
(gdb)

frame count should be 4, not 5.  This patch skips signal frames when
unwinding shadow stack.

gcc/testsuite/

	PR libgcc/85334
	* g++.dg/torture/pr85334.C: New test.

libgcc/

	PR libgcc/85334
	* unwind-generic.h (_Unwind_Frames_Increment): New.
	* config/i386/shadow-stack-unwind.h (_Unwind_Frames_Increment):
	Likewise.
	* unwind.inc (_Unwind_RaiseException_Phase2): Increment frame
	count with _Unwind_Frames_Increment.
	(_Unwind_ForcedUnwind_Phase2): Likewise.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259502 138bc75d-0d04-0410-961f-82ee72b054a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants