Skip to content

Latest commit

 

History

History
25 lines (21 loc) · 934 Bytes

现存问题.md

File metadata and controls

25 lines (21 loc) · 934 Bytes

GCC现存问题

当开启O2优化以后,编译器可能会将两个指针存入一个寄存器中,并在load指针时直接使用ld,以致load了一个64位数据导致程序崩溃

  如代码中所示,3f95dc处发生crash
    3f95d0:	60e2                	ld	ra,24(sp)
  ->3f95d2:	6398                	ld	a4,0(a5)
    3f95d4:	47cc                	lw	a1,12(a5)
    3f95d6:	42dc                	lw	a5,4(a3)
    3f95d8:	e518                	sd	a4,8(a0)
    3f95da:	cd4c                	sw	a1,28(a0)
  ->3f95dc:	c748                	sw	a0,12(a4)
    3f95de:	9301                	srl	a4,a4,0x20

现有改进思路:

 在riscv.cc  
  if (src_code == MEM)
switch (width)
  {
  case 1: return "lbu\t%0,%1";
  case 2: return "lhu\t%0,%1";
  case 4: return "lw\t%0,%1";
  case 8: return "ld\t%0,%1"; // if MEM_POINTER(src),return "ld\t%0,%1;sext.w\t%0,%0" 尝试中
  }