aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorNelson Chu <nelson.chu@sifive.com>2021-08-11 01:26:39 -0700
committerNelson Chu <nelson.chu@sifive.com>2021-11-19 09:32:19 +0800
commit8155b8539b55bca87378129e02009cd8907d8c8c (patch)
tree30524e98925e912c02387ae7b2bd0c58b9bb6ff4 /ld
parentfccf4ba5adaf69cac1875a194d8ee99dabf50c70 (diff)
downloadfsf-binutils-gdb-8155b8539b55bca87378129e02009cd8907d8c8c.zip
fsf-binutils-gdb-8155b8539b55bca87378129e02009cd8907d8c8c.tar.gz
fsf-binutils-gdb-8155b8539b55bca87378129e02009cd8907d8c8c.tar.bz2
RISC-V: Support STO_RISCV_VARIANT_CC and DT_RISCV_VARIANT_CC.
This is the original discussion, https://github.com/riscv/riscv-elf-psabi-doc/pull/190 And here is the glibc part, https://sourceware.org/pipermail/libc-alpha/2021-August/129931.html For binutils part, we need to support a new direcitve: .variant_cc. The function symbol marked by .variant_cc means it need to be resolved directly without resolver for dynamic linker. We also add a new dynamic entry, STO_RISCV_VARIANT_CC, to indicate there are symbols with the special attribute in the dynamic symbol table of the object. I heard that llvm already have supported this in their mainline, so I think it's time to commit this. bfd/ * elfnn-riscv.c (riscv_elf_link_hash_table): Added variant_cc flag. It is used to check if relocations for variant CC symbols may be present. (allocate_dynrelocs): If the symbol has STO_RISCV_VARIANT_CC flag, then raise the variant_cc flag of riscv_elf_link_hash_table. (riscv_elf_size_dynamic_sections): Added dynamic entry for variant_cc. (riscv_elf_merge_symbol_attribute): New function, used to merge non-visibility st_other attributes, including STO_RISCV_VARIANT_CC. binutils/ * readelf.c (get_riscv_dynamic_type): New function. (get_dynamic_type): Called get_riscv_dynamic_type for riscv targets. (get_riscv_symbol_other): New function. (get_symbol_other): Called get_riscv_symbol_other for riscv targets. gas/ * config/tc-riscv.c (s_variant_cc): Marked symbol that it follows a variant CC convention. (riscv_elf_copy_symbol_attributes): Same as elf_copy_symbol_attributes, but without copying st_other. If a function symbol has special st_other value set via directives, then attaching an IFUNC resolver to that symbol should not override the st_other setting. (riscv_pseudo_table): Support variant_cc diretive. * config/tc-riscv.h (OBJ_COPY_SYMBOL_ATTRIBUTES): Defined. * testsuite/gas/riscv/variant_cc-set.d: New testcase. * testsuite/gas/riscv/variant_cc-set.s: Likewise. * testsuite/gas/riscv/variant_cc.d: Likewise. * testsuite/gas/riscv/variant_cc.s: Likewise. include/ * elf/riscv.h (DT_RISCV_VARIANT_CC): Defined to (DT_LOPROC + 1). (STO_RISCV_VARIANT_CC): Defined to 0x80. ld/ * testsuite/ld-riscv-elf/variant_cc-1.s: New testcase. * testsuite/ld-riscv-elf/variant_cc-2.s: Likewise. * testsuite/ld-riscv-elf/variant_cc-now.d: Likewise. * testsuite/ld-riscv-elf/variant_cc-r.d: Likewise. * testsuite/ld-riscv-elf/variant_cc-shared.d: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
Diffstat (limited to 'ld')
-rw-r--r--ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp3
-rw-r--r--ld/testsuite/ld-riscv-elf/variant_cc-1.s61
-rw-r--r--ld/testsuite/ld-riscv-elf/variant_cc-2.s61
-rw-r--r--ld/testsuite/ld-riscv-elf/variant_cc-now.d73
-rw-r--r--ld/testsuite/ld-riscv-elf/variant_cc-r.d76
-rw-r--r--ld/testsuite/ld-riscv-elf/variant_cc-shared.d73
6 files changed, 347 insertions, 0 deletions
diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
index 78a7134..3bd7882 100644
--- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
+++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
@@ -169,6 +169,9 @@ if [istarget "riscv*-*-*"] {
run_dump_test "relro-relax-lui"
run_dump_test "relro-relax-pcrel"
+ run_dump_test "variant_cc-now"
+ run_dump_test "variant_cc-shared"
+ run_dump_test "variant_cc-r"
run_relax_twice_test
set abis [list rv32gc ilp32 [riscv_choose_ilp32_emul] rv64gc lp64 [riscv_choose_lp64_emul]]
diff --git a/ld/testsuite/ld-riscv-elf/variant_cc-1.s b/ld/testsuite/ld-riscv-elf/variant_cc-1.s
new file mode 100644
index 0000000..54ae162
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/variant_cc-1.s
@@ -0,0 +1,61 @@
+.text
+
+.variant_cc cc_global_default_def
+.variant_cc cc_global_default_undef
+.variant_cc cc_global_default_ifunc
+.variant_cc cc_global_hidden_def
+.variant_cc cc_global_hidden_ifunc
+.variant_cc cc_local
+.variant_cc cc_local_ifunc
+
+.global cc_global_default_def
+.global cc_global_default_undef
+.global cc_global_default_ifunc
+.global cc_global_hidden_def
+.global cc_global_hidden_ifunc
+.global nocc_global_default_def
+.global nocc_global_default_undef
+.global nocc_global_default_ifunc
+.global nocc_global_hidden_def
+.global nocc_global_hidden_ifunc
+
+.hidden cc_global_hidden_def
+.hidden cc_global_hidden_ifunc
+.hidden nocc_global_hidden_def
+.hidden nocc_global_hidden_ifunc
+
+.type cc_global_default_ifunc, %gnu_indirect_function
+.type cc_global_hidden_ifunc, %gnu_indirect_function
+.type cc_local_ifunc, %gnu_indirect_function
+.type nocc_global_default_ifunc, %gnu_indirect_function
+.type nocc_global_hidden_ifunc, %gnu_indirect_function
+.type nocc_local_ifunc, %gnu_indirect_function
+
+cc_global_default_def:
+# cc_global_default_undef:
+cc_global_hidden_def:
+cc_global_default_ifunc:
+cc_global_hidden_ifunc:
+cc_local:
+cc_local_ifunc:
+nocc_global_default_def:
+# nocc_global_default_undef:
+nocc_global_hidden_def:
+nocc_global_default_ifunc:
+nocc_global_hidden_ifunc:
+nocc_local:
+nocc_local_ifunc:
+ call cc_global_default_def
+ call cc_global_default_undef
+ call cc_global_hidden_def
+ call cc_global_default_ifunc
+ call cc_global_hidden_ifunc
+ call cc_local
+ call cc_local_ifunc
+ call nocc_global_default_def
+ call nocc_global_default_undef
+ call nocc_global_hidden_def
+ call nocc_global_default_ifunc
+ call nocc_global_hidden_ifunc
+ call nocc_local
+ call nocc_local_ifunc
diff --git a/ld/testsuite/ld-riscv-elf/variant_cc-2.s b/ld/testsuite/ld-riscv-elf/variant_cc-2.s
new file mode 100644
index 0000000..d7ca2d4
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/variant_cc-2.s
@@ -0,0 +1,61 @@
+.text
+
+.variant_cc cc_global_default_def
+.variant_cc cc_global_default_undef
+.variant_cc cc_global_default_ifunc
+.variant_cc cc_global_hidden_def
+.variant_cc cc_global_hidden_ifunc
+.variant_cc cc_local2
+.variant_cc cc_local2_ifunc
+
+.global cc_global_default_def
+.global cc_global_default_undef
+.global cc_global_default_ifunc
+.global cc_global_hidden_def
+.global cc_global_hidden_ifunc
+.global nocc_global_default_def
+.global nocc_global_default_undef
+.global nocc_global_default_ifunc
+.global nocc_global_hidden_def
+.global nocc_global_hidden_ifunc
+
+.hidden cc_global_hidden_def
+.hidden cc_global_hidden_ifunc
+.hidden nocc_global_hidden_def
+.hidden nocc_global_hidden_ifunc
+
+# .type cc_global_default_ifunc, %gnu_indirect_function
+# .type cc_global_hidden_ifunc, %gnu_indirect_function
+.type cc_local2_ifunc, %gnu_indirect_function
+# .type nocc_global_default_ifunc, %gnu_indirect_function
+# .type nocc_global_hidden_ifunc, %gnu_indirect_function
+.type nocc_local2_ifunc, %gnu_indirect_function
+
+# cc_global_default_def:
+# cc_global_default_undef:
+# cc_global_hidden_def:
+# cc_global_default_ifunc:
+# cc_global_hidden_ifunc:
+cc_local2:
+cc_local2_ifunc:
+# nocc_global_default_def:
+# nocc_global_default_undef:
+# nocc_global_hidden_def:
+# nocc_global_default_ifunc:
+# nocc_global_hidden_ifunc:
+nocc_local2:
+nocc_local2_ifunc:
+ call cc_global_default_def
+ call cc_global_default_undef
+ call cc_global_hidden_def
+ call cc_global_default_ifunc
+ call cc_global_hidden_ifunc
+ call cc_local2
+ call cc_local2_ifunc
+ call nocc_global_default_def
+ call nocc_global_default_undef
+ call nocc_global_hidden_def
+ call nocc_global_default_ifunc
+ call nocc_global_hidden_ifunc
+ call nocc_local2
+ call nocc_local2_ifunc
diff --git a/ld/testsuite/ld-riscv-elf/variant_cc-now.d b/ld/testsuite/ld-riscv-elf/variant_cc-now.d
new file mode 100644
index 0000000..9453554
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/variant_cc-now.d
@@ -0,0 +1,73 @@
+#source: variant_cc-1.s
+#source: variant_cc-2.s
+#ld: -shared --hash-style=sysv -Ttext 0x8000 -z now
+#readelf: -rsW
+
+Relocation section '.rela.plt' at .*
+#...
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+0+0000[ ]+nocc_global_default_undef \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+0+0000[ ]+cc_global_default_undef \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+0+8000[ ]+cc_global_default_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+0+8000[ ]+nocc_global_default_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+cc_global_default_ifunc\(\)[ ]+cc_global_default_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8000
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+nocc_global_default_ifunc\(\)[ ]+nocc_global_default_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8000
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8050
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8050
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8000
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8000
+#...
+Symbol table '.dynsym' contains .*
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+UND[ ]+nocc_global_default_undef
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+UND[ ]+cc_global_default_undef
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_def
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_def
+#...
+Symbol table '.symtab' contains .*
+.*
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+LOCAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_local
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+LOCAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_local_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+LOCAL[ ]+DEFAULT[ ]+1[ ]+nocc_local_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]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default_undef
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_def
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_def
+#...
diff --git a/ld/testsuite/ld-riscv-elf/variant_cc-r.d b/ld/testsuite/ld-riscv-elf/variant_cc-r.d
new file mode 100644
index 0000000..5235b8e
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/variant_cc-r.d
@@ -0,0 +1,76 @@
+#source: variant_cc-1.s
+#source: variant_cc-2.s
+#as: -mno-relax
+#ld: -r
+#readelf: -rsW
+
+Relocation section '.rela.text' at .*
+#...
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+cc_global_default_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+cc_global_default_undef \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+cc_global_hidden_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+cc_global_default_ifunc\(\)[ ]+cc_global_default_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+cc_global_hidden_ifunc\(\)[ ]+cc_global_hidden_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+cc_local \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+cc_local_ifunc\(\)[ ]+cc_local_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+nocc_global_default_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+nocc_global_default_undef \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+nocc_global_hidden_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+nocc_global_default_ifunc\(\)[ ]+nocc_global_default_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+nocc_global_hidden_ifunc\(\)[ ]+nocc_global_hidden_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+nocc_local \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+nocc_local_ifunc\(\)[ ]+nocc_local_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+cc_global_default_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+cc_global_default_undef \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+cc_global_hidden_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+cc_global_default_ifunc\(\)[ ]+cc_global_default_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+cc_global_hidden_ifunc\(\)[ ]+cc_global_hidden_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0070[ ]+cc_local2 \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+cc_local2_ifunc\(\)[ ]+cc_local2_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+nocc_global_default_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+nocc_global_default_undef \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0000[ ]+nocc_global_hidden_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+nocc_global_default_ifunc\(\)[ ]+nocc_global_default_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+nocc_global_hidden_ifunc\(\)[ ]+nocc_global_hidden_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+0+0070[ ]+nocc_local2 \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_CALL[ ]+nocc_local2_ifunc\(\)[ ]+nocc_local2_ifunc \+ 0
+#...
+Symbol table '.symtab' contains .*
+.*
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+LOCAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_local
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+IFUNC[ ]+LOCAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_local_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+IFUNC[ ]+LOCAL[ ]+DEFAULT[ ]+1[ ]+nocc_local_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+LOCAL[ ]+DEFAULT[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]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_def
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_def
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+HIDDEN[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_hidden_ifunc
+#...
diff --git a/ld/testsuite/ld-riscv-elf/variant_cc-shared.d b/ld/testsuite/ld-riscv-elf/variant_cc-shared.d
new file mode 100644
index 0000000..ffb69a3
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/variant_cc-shared.d
@@ -0,0 +1,73 @@
+#source: variant_cc-1.s
+#source: variant_cc-2.s
+#ld: -shared --hash-style=sysv -Ttext 0x8000
+#readelf: -rsW
+
+Relocation section '.rela.plt' at .*
+#...
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+0+0000[ ]+nocc_global_default_undef \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+0+0000[ ]+cc_global_default_undef \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+0+8000[ ]+cc_global_default_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+0+8000[ ]+nocc_global_default_def \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+cc_global_default_ifunc\(\)[ ]+cc_global_default_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8000
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_JUMP_SLOT[ ]+nocc_global_default_ifunc\(\)[ ]+nocc_global_default_ifunc \+ 0
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8000
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8050
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8050
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8000
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_RISCV_IRELATIVE[ ]+8000
+#...
+Symbol table '.dynsym' contains .*
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+UND[ ]+nocc_global_default_undef
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+UND[ ]+cc_global_default_undef
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_def
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_def
+#...
+Symbol table '.symtab' contains .*
+.*
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOT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000[ ]+0[ ]+IFUNC[ ]+LOCAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_hidden_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+UND[ ]+nocc_global_default_undef
+#...
+[ ]+[0-9a-f]+:[ ]+0+0000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+UND[ ]+cc_global_default_undef
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+IFUNC[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_ifunc
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+\[VARIANT_CC\][ ]+1[ ]+cc_global_default_def
+#...
+[ ]+[0-9a-f]+:[ ]+0+8000[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+1[ ]+nocc_global_default_def
+#...