From 3ab248e15214bed421f6266259e0dbd859a67bbe Mon Sep 17 00:00:00 2001 From: Xing Li Date: Thu, 5 Jan 2023 17:08:14 +0800 Subject: [PATCH] LoongArch: Fixup gas SIGSEGV for extremely long function name Signed-off-by: Xing Li --- ...ment-error-in-compilation-due-to-too.patch | 121 ++++++++++++++++++ binutils.spec | 7 +- 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Fix-gas-bug-Segment-error-in-compilation-due-to-too.patch diff --git a/Fix-gas-bug-Segment-error-in-compilation-due-to-too.patch b/Fix-gas-bug-Segment-error-in-compilation-due-to-too.patch new file mode 100644 index 0000000..503bd73 --- /dev/null +++ b/Fix-gas-bug-Segment-error-in-compilation-due-to-too.patch @@ -0,0 +1,121 @@ +From a74d8d8d9f7f05666ff34d27ac22cecb61c88a4b Mon Sep 17 00:00:00 2001 +From: Xing Li +Date: Thu, 5 Jan 2023 15:49:52 +0800 +Subject: [PATCH] Fix gas bug: Segment error in compilation due to too + long symbol name. + + change "char buffer[8192];" into "char *buffer = + (char *) malloc(1000 + 6 * len_str);"in function + loongarch_expand_macro_with_format_map. + + gas/config/tc-loongarch.c + include/opcode/loongarch.h + opcodes/loongarch-coder.c + +Signed-off-by: Xing Li +--- + gas/config/tc-loongarch.c | 7 +++++-- + include/opcode/loongarch.h | 4 ++-- + opcodes/loongarch-coder.c | 15 ++++++++++----- + 3 files changed, 17 insertions(+), 9 deletions(-) + +diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c +index 26ee3f1a..9ab015a3 100644 +--- a/gas/config/tc-loongarch.c ++++ b/gas/config/tc-loongarch.c +@@ -921,7 +921,8 @@ assember_macro_helper (const char * const args[], void *context_ptr) + } + while (0); + +- ret = loongarch_expand_macro (insns_buf, arg_strs, NULL, NULL); ++ ret = loongarch_expand_macro (insns_buf, arg_strs, NULL, NULL, ++ sizeof (args_buf)); + } + return ret; + } +@@ -932,6 +933,7 @@ static void + loongarch_assemble_INSNs (char *str) + { + char *rest; ++ size_t len_str = strlen(str); + + for (rest = str; *rest != ';' && *rest != '\0'; rest++); + if (*rest == ';') +@@ -971,7 +973,8 @@ loongarch_assemble_INSNs (char *str) + { + char *c_str = + loongarch_expand_macro (the_one.insn->macro, +- the_one.arg_strs, assember_macro_helper, &the_one); ++ the_one.arg_strs, assember_macro_helper, ++ &the_one, len_str); + loongarch_assemble_INSNs (c_str); + free (c_str); + } +diff --git a/include/opcode/loongarch.h b/include/opcode/loongarch.h +index 47a9d94b..fc0be236 100644 +--- a/include/opcode/loongarch.h ++++ b/include/opcode/loongarch.h +@@ -151,12 +151,12 @@ loongarch_expand_macro_with_format_map (const char *format, const char *macro, + char * (*helper) ( + const char * const arg_strs[], + void *context), +- void *context); ++ void *context, size_t len_str); + extern char * + loongarch_expand_macro (const char *macro, const char * const arg_strs[], + char * (*helper) (const char * const arg_strs[], + void *context), +- void *context); ++ void *context, size_t len_str); + extern size_t + loongarch_bits_imm_needed (int64_t imm, int si); + +diff --git a/opcodes/loongarch-coder.c b/opcodes/loongarch-coder.c +index 399af4f0..aa6a2388 100644 +--- a/opcodes/loongarch-coder.c ++++ b/opcodes/loongarch-coder.c +@@ -352,13 +352,18 @@ loongarch_expand_macro_with_format_map (const char *format, const char *macro, + char * (*helper) ( + const char * const arg_strs[], + void *context), +- void *context) ++ void *context, size_t len_str) + { + char esc1s[MAX_ARG_NUM_PLUS_2 - 1], esc2s[MAX_ARG_NUM_PLUS_2 - 1]; + const char *bit_fields[MAX_ARG_NUM_PLUS_2 - 1]; + const char *src; + char *dest; +- char buffer[8192]; ++ ++ /*The expanded macro character length does not exceed 1000, and number of ++ * label is 6 at most in the expanded macro. The len_str is the length of ++ * str. ++ */ ++ char *buffer = (char *) malloc(1000 + 6 * len_str); + + if (format) + loongarch_parse_format (format, esc1s, esc2s, bit_fields); +@@ -396,17 +401,17 @@ loongarch_expand_macro_with_format_map (const char *format, const char *macro, + *dest++ = *src++; + + *dest = '\0'; +- return strdup (buffer); ++ return buffer; + } + + char * + loongarch_expand_macro (const char *macro, const char * const arg_strs[], + char * (*helper) (const char * const arg_strs[], + void *context), +- void *context) ++ void *context, size_t len_str) + { + return loongarch_expand_macro_with_format_map +- (NULL, macro, arg_strs, I, helper, context); ++ (NULL, macro, arg_strs, I, helper, context, len_str); + } + + size_t +-- +2.27.0 + diff --git a/binutils.spec b/binutils.spec index 95dd849..7d7df11 100644 --- a/binutils.spec +++ b/binutils.spec @@ -24,7 +24,7 @@ # /usr/bin/aarch64-linux-gnu-ar # /usr/bin/aarch64-linux-gnu-as # [etc] -%define anolis_release .0.1 +%define anolis_release .0.2 %if 0%{!?binutils_target:1} @@ -634,6 +634,7 @@ Patch1000: 0001-binutils-anolis-rebrand.patch Patch1001: binutils-loongarch-support.patch Patch1002: 0001-LoongArch-Fix-wrong-line-number-in-.debug_line.patch Patch1003: binutils-LoongArch-Add-missing-opcode.patch +Patch1004: Fix-gas-bug-Segment-error-in-compilation-due-to-too.patch #end #---------------------------------------------------------------------------- @@ -880,6 +881,7 @@ using libelf instead of BFD. %patch1001 -p1 %patch1002 -p1 %patch1003 -p1 +%patch1004 -p1 # We cannot run autotools as there is an exact requirement of autoconf-2.59. # FIXME - this is no longer true. Maybe try reinstating autotool use ? @@ -1329,6 +1331,9 @@ exit 0 #---------------------------------------------------------------------------- %changelog +* Thu Jan 5 2023 Xing Li - 2.30-117.0.2 +- Fixup gas SIGSEGV for extremely long function name. (lixing@loongson.cn) + * Tue Dec 27 2022 Xue haolin - 2.30-117.0.1 - Rebrand to Anolis OS. - Add loongarch support. (lixing@loongson.cn) -- Gitee