|
| 1 | +From 03c88b26a6d9cedb201699e435fe685e5131a33e Mon Sep 17 00:00:00 2001 |
| 2 | +From: "H.J. Lu" < [email protected]> |
| 3 | +Date: Tue, 23 Sep 2025 08:52:26 +0800 |
| 4 | +Subject: [PATCH] elf: Return error on unsorted symbol table if not allowed |
| 5 | + |
| 6 | +Normally ELF symbol table should be sorted, i.e., local symbols precede |
| 7 | +global symbols. Irix 6 is an exception and its elf_bad_symtab is set |
| 8 | +to true. Issue an error if elf_bad_symtab is false and symbol table is |
| 9 | +unsorted. |
| 10 | + |
| 11 | + PR ld/33450 |
| 12 | + * elflink.c (set_symbol_value): Change return type to bool and |
| 13 | + return false on error. Issue an error on unsorted symbol table |
| 14 | + if not allowed. |
| 15 | + (elf_link_input_bfd): Return false if set_symbol_value reurns |
| 16 | + false. |
| 17 | + |
| 18 | +Signed-off-by: H.J. Lu < [email protected]> |
| 19 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 20 | +Upstream-reference: https://github.com/bminor/binutils-gdb/commit/aeaaa9af6359c8e394ce9cf24911fec4f4d23703.patch |
| 21 | +--- |
| 22 | + bfd/elflink.c | 21 +++++++++++++++------ |
| 23 | + 1 file changed, 15 insertions(+), 6 deletions(-) |
| 24 | + |
| 25 | +diff --git a/bfd/elflink.c b/bfd/elflink.c |
| 26 | +index 3ec41fd5..1a86f9d2 100644 |
| 27 | +--- a/bfd/elflink.c |
| 28 | ++++ b/bfd/elflink.c |
| 29 | +@@ -8846,7 +8846,7 @@ struct elf_outext_info |
| 30 | + <binary-operator> := as in C |
| 31 | + <unary-operator> := as in C, plus "0-" for unambiguous negation. */ |
| 32 | + |
| 33 | +-static void |
| 34 | ++static bool |
| 35 | + set_symbol_value (bfd *bfd_with_globals, |
| 36 | + Elf_Internal_Sym *isymbuf, |
| 37 | + size_t locsymcount, |
| 38 | +@@ -8867,9 +8867,15 @@ set_symbol_value (bfd *bfd_with_globals, |
| 39 | + "absolute" section and give it a value. */ |
| 40 | + sym->st_shndx = SHN_ABS; |
| 41 | + sym->st_value = val; |
| 42 | +- return; |
| 43 | ++ return true; |
| 44 | ++ } |
| 45 | ++ if (!elf_bad_symtab (bfd_with_globals)) |
| 46 | ++ { |
| 47 | ++ _bfd_error_handler (_("%pB: corrupt symbol table"), |
| 48 | ++ bfd_with_globals); |
| 49 | ++ bfd_set_error (bfd_error_bad_value); |
| 50 | ++ return false; |
| 51 | + } |
| 52 | +- BFD_ASSERT (elf_bad_symtab (bfd_with_globals)); |
| 53 | + extsymoff = 0; |
| 54 | + } |
| 55 | + |
| 56 | +@@ -8879,11 +8885,12 @@ set_symbol_value (bfd *bfd_with_globals, |
| 57 | + if (h == NULL) |
| 58 | + { |
| 59 | + /* FIXMEL What should we do ? */ |
| 60 | +- return; |
| 61 | ++ return false; |
| 62 | + } |
| 63 | + h->root.type = bfd_link_hash_defined; |
| 64 | + h->root.u.def.value = val; |
| 65 | + h->root.u.def.section = bfd_abs_section_ptr; |
| 66 | ++ return true; |
| 67 | + } |
| 68 | + |
| 69 | + static bool |
| 70 | +@@ -11573,8 +11580,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd) |
| 71 | + return false; |
| 72 | + |
| 73 | + /* Symbol evaluated OK. Update to absolute value. */ |
| 74 | +- set_symbol_value (input_bfd, isymbuf, locsymcount, |
| 75 | +- r_symndx, val); |
| 76 | ++ if (!set_symbol_value (input_bfd, isymbuf, locsymcount, r_symndx, |
| 77 | ++ val)) |
| 78 | ++ return false; |
| 79 | ++ |
| 80 | + continue; |
| 81 | + } |
| 82 | + |
| 83 | +-- |
| 84 | +2.45.4 |
| 85 | + |
0 commit comments