From: Jim Wilson Date: Tue, 25 Sep 2018 22:52:38 +0000 (+0000) Subject: RISC-V: Fix weak symbols with medany and explicit relocs. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ad117173a0d8a5412bc2b9fb99e2c9b1cb4036af;p=gcc.git RISC-V: Fix weak symbols with medany and explicit relocs. gcc/ * config/riscv/riscv.c (riscv_split_symbol): Mark auipc label as weak when target symbol is weak. gcc/testsuite/ * gcc.target/riscv/weak-1.c: New. From-SVN: r264586 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 43857153e9f..d43e6d682cc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-09-25 Jim Wilson + + * config/riscv/riscv.c (riscv_split_symbol): Mark auipc label as weak + when target symbol is weak. + 2018-09-25 Bernd Edlinger PR c/87387 diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index 9d6d981a42a..381a203da9b 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -1103,6 +1103,11 @@ riscv_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out) label = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); SYMBOL_REF_FLAGS (label) |= SYMBOL_FLAG_LOCAL; + /* ??? Ugly hack to make weak symbols work. May need to change the + RTL for the auipc and/or low patterns to get a better fix for + this. */ + if (! nonzero_address_p (addr)) + SYMBOL_REF_WEAK (label) = 1; if (temp == NULL) temp = gen_reg_rtx (Pmode); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7b26b894b15..f690e62a445 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-09-25 Jim Wilson + + * gcc.target/riscv/weak-1.c: New. + 2018-09-25 Jeff Law * gcc.dg/warn-stpcpy-no-nul.c: Drop unnecessary xfails. diff --git a/gcc/testsuite/gcc.target/riscv/weak-1.c b/gcc/testsuite/gcc.target/riscv/weak-1.c new file mode 100644 index 00000000000..0f20501f7c5 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/weak-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-mcmodel=medany -mexplicit-relocs -O" } */ + +/* Verify that the branch doesn't get optimized away. */ +extern int weak_func(void) __attribute__ ((weak)); + +int +sub (void) +{ + if (weak_func) + return weak_func (); + return 0; +} +/* { dg-final { scan-assembler "b\(ne|eq\)" } } */