1 Star 0 Fork 25

Zhao Hang/binutils

forked from src-anolis-os/binutils 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Fix-gas-bug-Segment-error-in-compilation-due-to-too.patch 3.86 KB
一键复制 编辑 原始数据 按行查看 历史
lixing.loongson.cn 提交于 2023-07-18 15:03 . Fixup some bugs for LoongArch
From a74d8d8d9f7f05666ff34d27ac22cecb61c88a4b Mon Sep 17 00:00:00 2001
From: Xing Li <lixing@loongson.cn>
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 <lixing@loongson.cn>
---
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhaohang_mskdxl/binutils.git
git@gitee.com:zhaohang_mskdxl/binutils.git
zhaohang_mskdxl
binutils
binutils
a8

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385