https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93202

            Bug ID: 93202
           Summary: [RISCV] ICE when using inline asm 'h' constraint
                    modifier
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luismarques at lowrisc dot org
  Target Milestone: ---

In some cases using the inline assembly 'h' constraint modifier results in
crashes. Tested with mainline GCC. Some examples:

[test.c]
int x;
int main() {
    asm volatile("%h0" :: "i"(&x));
    return 0;
}

$ riscv64-unknown-linux-gnu-gcc -S -o- test.c

[stdout]
(...)
        %hi(x)
(...)

$ riscv64-unknown-linux-gnu-gcc -S -o- -fPIC test.c

test.c: In function 'main':
test.c:5:1: internal compiler error: in riscv_print_operand_reloc, at
config/riscv/riscv.c:3191
    5 | }

[test.c]
__thread int x;
int main() {
    asm volatile("%h0" :: "i"(&x));
    return 0;
}

$ riscv64-unknown-linux-gnu-gcc -S -o- test.c

test.c: In function 'main':
test.c:5:1: internal compiler error: in riscv_print_operand_reloc, at
config/riscv/riscv.c:3191
    5 | }
      | ^

[test.c]
void foo() {}

int main() {
    asm volatile("%h0" :: "i"(&foo));
    return 0;
}

$ riscv64-unknown-linux-gnu-gcc -S -o- -fPIC test.c

test.c: In function 'main':
test.c:6:1: internal compiler error: in riscv_print_operand_reloc, at
config/riscv/riscv.c:3191
    6 | }
      | ^

$ riscv64-unknown-linux-gnu-gcc -S -o- -fPIE test.c

[stdout]
(...)
        %pcrel_hi(foo)
(...)


The function in [1] only handles `SYMBOL_ABSOLUTE`, `SYMBOL_PCREL` and
`SYMBOL_TLS_LE`, and apparently in the other cases GCC generates something else
(maybe something GOT-related?) and we reach the `gcc_unreachable`.

I would also appreciate if you could provide some clarity about when the "after
stripping any outermost HIGH" in the following description [2] applies:

  'h': Print the high-part relocation associated with OP, after stripping any
outermost HIGH.

[1]
https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/riscv/riscv.c?view=markup&revision=271293#l3101
[2]
https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/riscv/riscv.c?view=markup&revision=271293#l3181

Reply via email to