From 09a7e912932db766d5e6badfcba61c55f185503a Mon Sep 17 00:00:00 2001 From: Claudiu Zissulescu Date: Tue, 14 Sep 2021 12:10:54 +0300 Subject: arc: Fix potential invalid pointer access when fixing got symbols. When statically linking, it can arrive to an undefined weak symbol of which its value cannot be determined. However, we are having pieces of code which doesn't take this situation into account, leading to access a structure which may not be initialized. Fix this situation and add a test. bfd/ xxxx-xx-xx Cupertino Miranda Claudiu Zissulescu * arc-got.h (arc_static_sym_data): New structure. (get_static_sym_data): New function. (relocate_fix_got_relocs_for_got_info): Move the computation fo symbol value and section to above introduced function, and use this new function. ld/testsuite/ xxxx-xx-xx Claudiu Zissulescu * ld-arc/got-weak.d: New file. * ld-arc/got-weak.s: Likewise. Signed-off-by: Claudiu Zissulescu fix --- ld/testsuite/ld-arc/got-weak.d | 12 ++++++++++++ ld/testsuite/ld-arc/got-weak.s | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 ld/testsuite/ld-arc/got-weak.d create mode 100644 ld/testsuite/ld-arc/got-weak.s (limited to 'ld/testsuite') diff --git a/ld/testsuite/ld-arc/got-weak.d b/ld/testsuite/ld-arc/got-weak.d new file mode 100644 index 0000000..cf15069 --- /dev/null +++ b/ld/testsuite/ld-arc/got-weak.d @@ -0,0 +1,12 @@ +#source: got-weak.s +#as: +#ld: -Bstatic +#objdump: -d + +[^:]*: file format elf32-.*arc + + +Disassembly of section \.text: + +00000100 <.*>: + 100: 2730 7f80 0000 2014 ld r0,\[pcl,0x2014\].* diff --git a/ld/testsuite/ld-arc/got-weak.s b/ld/testsuite/ld-arc/got-weak.s new file mode 100644 index 0000000..8ea18be --- /dev/null +++ b/ld/testsuite/ld-arc/got-weak.s @@ -0,0 +1,7 @@ + .cpu archs + + .weak symb + .global __start + .text +__start: + ld r0,[pcl,@symb@gotpc] -- cgit v1.1