1 Star 0 Fork 25

lixing.loongson.cn/binutils_anolis

forked from src-anolis-os/binutils 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
binutils-Delete-warning-of-compile.patch 31.81 KB
一键复制 编辑 原始数据 按行查看 历史
lixing.loongson.cn 提交于 2023-07-18 15:03 . Fixup some bugs for LoongArch
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
From 095ac9fd7c2128c0ad31f71cc9725d0a21500c2a Mon Sep 17 00:00:00 2001
From: Xing Li <lixing@loongson.cn>
Date: Tue, 18 Jul 2023 13:34:53 +0800
Subject: [PATCH 3/3] binutils: Delete warning of compile
---
bfd/elfnn-loongarch.c | 617 ++++++++++++++++++++---------------
gas/config/loongarch-lex.l | 3 +
gas/config/loongarch-parse.y | 9 +-
gas/config/tc-loongarch.c | 44 +--
opcodes/loongarch-dis.c | 8 +-
5 files changed, 385 insertions(+), 296 deletions(-)
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index ca29aaea..5582107e 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -585,7 +585,7 @@ loongarch_elf_record_tls_and_got_reference (bfd *abfd,
/* no need for GOT */
break;
default:
- _bfd_error_handler (_("%pB: Interl error: unreachable."));
+ _bfd_error_handler (_("%pB: Interl error: unreachable."), abfd);
return FALSE;
}
@@ -1107,7 +1107,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
&& h->def_regular)
return TRUE;
- eh = (struct loongarch_elf_link_hash_entry *) h;
info = (struct bfd_link_info *) inf;
htab = loongarch_elf_hash_table (info);
BFD_ASSERT (htab != NULL);
@@ -1284,7 +1283,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
/* Allocate space in .plt, .got and associated reloc sections for
ifunc dynamic relocs. */
-static bfd_boolean
+static bfd_boolean
elfNN_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h, void *inf)
{
struct bfd_link_info *info;
@@ -1339,21 +1338,6 @@ elfNN_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
return elfNN_allocate_ifunc_dynrelocs (h, inf);
}
-static bfd_boolean
-elfNN_loongarch_allocate_local_dynrelocs (void **slot, void *inf)
-{
- struct elf_link_hash_entry *h
- = (struct elf_link_hash_entry *) *slot;
-
- if (!h->def_regular
- || !h->ref_regular
- || !h->forced_local
- || h->root.type != bfd_link_hash_defined)
- abort ();
-
- return allocate_dynrelocs (h, inf);
-}
-
/* Set DF_TEXTREL if we find any dynamic relocs that apply to
read-only sections. */
@@ -2055,6 +2039,50 @@ loongarch_dump_reloc_record (void (*p) (const char *fmt, ...))
p ("\n" "-- Record dump end --\n\n");
}
+static bfd_boolean
+loongarch_reloc_is_fatal (struct bfd_link_info *info,
+ bfd *input_bfd,
+ asection *input_section,
+ Elf_Internal_Rela *rel,
+ reloc_howto_type *howto,
+ bfd_reloc_status_type rtype,
+ bfd_boolean is_undefweak,
+ const char *name,
+ const char *msg)
+{
+ bfd_boolean fatal = TRUE;
+
+ switch (rtype)
+ {
+ /* 'dangerous' means we do it but can't promise it's ok
+ 'unsupport' means out of ability of relocation type
+ 'undefined' means we can't deal with the undefined symbol. */
+ case bfd_reloc_undefined:
+ info->callbacks->undefined_symbol (info, name, input_bfd, input_section,
+ rel->r_offset, TRUE);
+ info->callbacks->info ("%X%pB(%pA+0x%v): error: %s against %s`%s':\n%s\n",
+ input_bfd, input_section, rel->r_offset,
+ howto->name,
+ is_undefweak ? "[undefweak] " : "", name, msg);
+ break;
+ case bfd_reloc_dangerous:
+ info->callbacks->info ("%pB(%pA+0x%v): warning: %s against %s`%s':\n%s\n",
+ input_bfd, input_section, rel->r_offset,
+ howto->name,
+ is_undefweak ? "[undefweak] " : "", name, msg);
+ fatal = FALSE;
+ break;
+ case bfd_reloc_notsupported:
+ info->callbacks->info ("%X%pB(%pA+0x%v): error: %s against %s`%s':\n%s\n",
+ input_bfd, input_section, rel->r_offset,
+ howto->name,
+ is_undefweak ? "[undefweak] " : "", name, msg);
+ break;
+ default:
+ break;
+ }
+ return fatal;
+}
static bfd_boolean
loongarch_elf_relocate_section (bfd *output_bfd,
@@ -2209,12 +2237,6 @@ loongarch_elf_relocate_section (bfd *output_bfd,
b. 此外,比如代码段的重定位无法动态改变其的引用位置,所以必须走plt
来实现IFUNC。
c. 因此,为方便实现,我们将plt stub的位置当作IFUNC符号的定义。 */
- if (h->plt.offset == MINUS_ONE)
- info->callbacks->info
- ("%X%pB(%pA+0x%v): error: %s against `%s':\n"
- "STT_GNU_IFUNC must have PLT stub" "\n",
- input_bfd, input_section, (bfd_vma) rel->r_offset,
- howto->name, name);
defined_local = TRUE;
resolved_local = TRUE;
resolved_dynly = FALSE;
@@ -2239,42 +2261,6 @@ loongarch_elf_relocate_section (bfd *output_bfd,
is_ie = FALSE;
switch (r_type)
{
-#define LARCH_ASSERT(cond, bfd_fail_state, message) \
- ({if (!(cond)) { \
- r = bfd_fail_state; \
- switch (r) { \
- /* 'dangerous' means we do it but can't promise it's ok \
- 'unsupport' means out of ability of relocation type \
- 'undefined' means we can't deal with the undefined symbol */ \
- case bfd_reloc_undefined: \
- info->callbacks->undefined_symbol \
- (info, name, input_bfd, input_section, rel->r_offset, TRUE); \
- default: \
- fatal = TRUE; \
- info->callbacks->info \
- ("%X%pB(%pA+0x%v): error: %s against %s`%s':\n" \
- message "\n", \
- input_bfd, input_section, (bfd_vma) rel->r_offset, \
- howto->name, is_undefweak? "[undefweak] " : "", name); \
- break; \
- case bfd_reloc_dangerous: \
- info->callbacks->info \
- ("%pB(%pA+0x%v): warning: %s against %s`%s':\n" \
- message "\n", \
- input_bfd, input_section, (bfd_vma) rel->r_offset, \
- howto->name, is_undefweak? "[undefweak] " : "", name); \
- break; \
- case bfd_reloc_ok: \
- case bfd_reloc_continue: \
- info->callbacks->info \
- ("%pB(%pA+0x%v): message: %s against %s`%s':\n" \
- message "\n", \
- input_bfd, input_section, (bfd_vma) rel->r_offset, \
- howto->name, is_undefweak? "[undefweak] " : "", name); \
- break; \
- } \
- if (fatal) break; \
- }})
case R_LARCH_MARK_PCREL:
case R_LARCH_MARK_LA:
case R_LARCH_NONE:
@@ -2377,11 +2363,18 @@ loongarch_elf_relocate_section (bfd *output_bfd,
case R_LARCH_SUB24:
case R_LARCH_SUB32:
case R_LARCH_SUB64:
- LARCH_ASSERT (!resolved_dynly, bfd_reloc_undefined,
-"Can't be resolved dynamically. If this procedure is hand-writing assemble,\n"
-"there must be something like '.dword sym1 - sym2' to generate these relocs\n"
-"and we can't get known link-time address of these symbols.");
- relocation += rel->r_addend;
+ if (resolved_dynly)
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_undefined, is_undefweak, name,
+ "Can't be resolved dynamically. "
+ "If this procedure is hand-written assembly,\n"
+ "there must be something like '.dword sym1 - sym2' "
+ "to generate these relocs\n"
+ "and we can't get known link-time address of "
+ "these symbols."));
+ else
+ relocation += rel->r_addend;
break;
case R_LARCH_TLS_DTPREL32:
@@ -2390,12 +2383,11 @@ loongarch_elf_relocate_section (bfd *output_bfd,
{
Elf_Internal_Rela outrel;
- outrel.r_offset =
- _bfd_elf_section_offset (output_bfd, info, input_section,
- rel->r_offset);
-
- unresolved_reloc = !((bfd_vma) -2 <= outrel.r_offset)
- && (input_section->flags & SEC_ALLOC);
+ outrel.r_offset = _bfd_elf_section_offset (output_bfd, info,
+ input_section,
+ rel->r_offset);
+ unresolved_reloc = (!((bfd_vma) -2 <= outrel.r_offset)
+ && (input_section->flags & SEC_ALLOC));
outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
outrel.r_offset += sec_addr (input_section);
outrel.r_addend = rel->r_addend;
@@ -2404,28 +2396,67 @@ loongarch_elf_relocate_section (bfd *output_bfd,
break;
}
- LARCH_ASSERT (!resolved_to_const, bfd_reloc_notsupported,
- "Internal:");
+ if (resolved_to_const)
+ fatal = loongarch_reloc_is_fatal (info, input_bfd, input_section,
+ rel, howto,
+ bfd_reloc_notsupported,
+ is_undefweak, name,
+ "Internal:");
+ if (resolved_local)
+ {
+ if (!elf_hash_table (info)->tls_sec)
+ {
+ fatal = loongarch_reloc_is_fatal (info, input_bfd,
+ input_section, rel, howto, bfd_reloc_notsupported,
+ is_undefweak, name, "TLS section not be created");
+ }
+ else
+ relocation -= elf_hash_table (info)->tls_sec->vma;
+ }
+ else
+ {
+ fatal = loongarch_reloc_is_fatal (info, input_bfd,
+ input_section, rel, howto, bfd_reloc_undefined,
+ is_undefweak, name,
+ "TLS LE just can be resolved local only.");
+ }
+ break;
+
case R_LARCH_SOP_PUSH_TLS_TPREL:
if (resolved_local)
{
- LARCH_ASSERT (elf_hash_table (info)->tls_sec,
- bfd_reloc_notsupported, "TLS section not be created");
- relocation -= elf_hash_table (info)->tls_sec->vma;
+ if (!elf_hash_table (info)->tls_sec)
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "TLS section not be created"));
+ else
+ relocation -= elf_hash_table (info)->tls_sec->vma;
}
+ else
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_undefined, is_undefweak, name,
+ "TLS LE just can be resolved local only."));
- LARCH_ASSERT (resolved_local, bfd_reloc_undefined,
- "TLS LE just can be resolved local only.");
break;
case R_LARCH_SOP_PUSH_ABSOLUTE:
if (is_undefweak)
{
- LARCH_ASSERT (!resolved_dynly, bfd_reloc_dangerous,
-"Someone require us to resolve undefweak symbol dynamically.\n"
-"But this reloc can't be done. I think I can't throw error for this\n"
-"so I resolved it to 0. I suggest to re-compile with '-fpic'.");
+ if (resolved_dynly)
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_dangerous, is_undefweak, name,
+ "Someone require us to resolve undefweak "
+ "symbol dynamically. \n"
+ "But this reloc can't be done. "
+ "I think I can't throw error "
+ "for this\n"
+ "so I resolved it to 0. "
+ "I suggest to re-compile with '-fpic'."));
+
relocation = 0;
unresolved_reloc = FALSE;
break;
@@ -2437,17 +2468,36 @@ loongarch_elf_relocate_section (bfd *output_bfd,
break;
}
- LARCH_ASSERT (!is_pic, bfd_reloc_notsupported,
-"Under PIC we don't know load address. Re-compile src with '-fpic'?");
+ if (is_pic)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "Under PIC we don't know load address. Re-compile "
+ "with '-fpic'?"));
+ break;
+ }
if (resolved_dynly)
{
- LARCH_ASSERT (plt && h && h->plt.offset != MINUS_ONE,
- bfd_reloc_undefined,
-"Can't be resolved dynamically. Try to re-compile src with '-fpic'?");
+ if (!(plt && h && h->plt.offset != MINUS_ONE))
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_undefined, is_undefweak, name,
+ "Can't be resolved dynamically. Try to re-compile "
+ "with '-fpic'?"));
+ break;
+ }
- LARCH_ASSERT (rel->r_addend == 0, bfd_reloc_notsupported,
- "Shouldn't be with r_addend.");
+ if (rel->r_addend != 0)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "Shouldn't be with r_addend."));
+ break;
+ }
relocation = sec_addr (plt) + h->plt.offset;
unresolved_reloc = FALSE;
@@ -2466,12 +2516,12 @@ loongarch_elf_relocate_section (bfd *output_bfd,
case R_LARCH_SOP_PUSH_PLT_PCREL:
unresolved_reloc = FALSE;
- if (resolved_to_const)
- {
- relocation += rel->r_addend;
- break;
- }
- else if (is_undefweak)
+ if (resolved_to_const)
+ {
+ relocation += rel->r_addend;
+ break;
+ }
+ else if (is_undefweak)
{
i = 0, j = 0;
relocation = 0;
@@ -2480,24 +2530,36 @@ loongarch_elf_relocate_section (bfd *output_bfd,
if (h && h->plt.offset != MINUS_ONE)
i = 1, j = 2;
else
- LARCH_ASSERT (0, bfd_reloc_dangerous,
-"Undefweak need to be resolved dynamically, but PLT stub doesn't represent.");
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_dangerous, is_undefweak, name,
+ "Undefweak need to be resolved dynamically, "
+ "but PLT stub doesn't represent."));
}
}
else
{
- LARCH_ASSERT
- (defined_local || (h && h->plt.offset != MINUS_ONE),
- bfd_reloc_undefined,
- "PLT stub does not represent and symbol not defined.");
+ if (!(defined_local || (h && h->plt.offset != MINUS_ONE)))
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_undefined, is_undefweak, name,
+ "PLT stub does not represent and "
+ "symbol not defined."));
+ break;
+ }
if (resolved_local)
i = 0, j = 2;
else /* if (resolved_dynly) */
{
- LARCH_ASSERT
- (h && h->plt.offset != MINUS_ONE, bfd_reloc_dangerous,
-"Internal: PLT stub doesn't represent. Resolve it with pcrel");
+ if (!(h && h->plt.offset != MINUS_ONE))
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_dangerous, is_undefweak, name,
+ "Internal: PLT stub doesn't represent. "
+ "Resolve it with pcrel"));
+
i = 1, j = 3;
}
}
@@ -2513,8 +2575,15 @@ loongarch_elf_relocate_section (bfd *output_bfd,
if ((i & 1) && h && h->plt.offset != MINUS_ONE)
{
- LARCH_ASSERT (rel->r_addend == 0, bfd_reloc_notsupported,
- "PLT shouldn't be with r_addend.");
+ if (rel->r_addend != 0)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "PLT shouldn't be with r_addend."));
+ break;
+ }
+
relocation = sec_addr (plt) + h->plt.offset - pc;
break;
}
@@ -2524,24 +2593,36 @@ loongarch_elf_relocate_section (bfd *output_bfd,
case R_LARCH_SOP_PUSH_GPREL:
unresolved_reloc = FALSE;
- LARCH_ASSERT (rel->r_addend == 0, bfd_reloc_notsupported,
- "Shouldn't be with r_addend.");
-
+ if (rel->r_addend != 0)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "Shouldn't be with r_addend."));
+ break;
+ }
if (h != NULL)
{
off = h->got.offset & (~1);
- LARCH_ASSERT (!(h->got.offset == MINUS_ONE
- && h->type != STT_GNU_IFUNC),
- bfd_reloc_notsupported,
- "Internal: GOT entry doesn't represent.");
+ if (h->got.offset == MINUS_ONE && h->type != STT_GNU_IFUNC)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "Internal: GOT entry doesn't represent."));
+ break;
+ }
/* Hidden symbol not has .got entry, only .got.plt entry
so gprel is (plt - got). */
if (h->got.offset == MINUS_ONE && h->type == STT_GNU_IFUNC)
{
- BFD_ASSERT(h->plt.offset != (bfd_vma) -1);
+ if (h->plt.offset == (bfd_vma) -1)
+ {
+ abort();
+ }
bfd_vma plt_index = h->plt.offset / PLT_ENTRY_SIZE;
off = plt_index * GOT_ENTRY_SIZE;
@@ -2580,17 +2661,37 @@ loongarch_elf_relocate_section (bfd *output_bfd,
relocation entry to initialize the value. This
is done in the finish_dynamic_symbol routine. */
- LARCH_ASSERT (!resolved_dynly || (defined_local || resolved_to_const),
- bfd_reloc_notsupported,
- "Internal: here shouldn't dynamic.");
-
+ if (resolved_dynly)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_dangerous, is_undefweak, name,
+ "Internal: here shouldn't dynamic."));
+ }
+
+ if (!(defined_local || resolved_to_const))
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_undefined, is_undefweak, name,
+ "Internal: "));
+ break;
+ }
+
asection *s;
Elf_Internal_Rela outrel;
/* We need to generate a R_LARCH_RELATIVE reloc
for the dynamic linker. */
s = htab->elf.srelgot;
- LARCH_ASSERT (s, bfd_reloc_notsupported,
- "Internal: '.rel.got' not represent.");
+ if (!s)
+ {
+ fatal = loongarch_reloc_is_fatal
+ (info, input_bfd,
+ input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "Internal: '.rel.got' not represent");
+ break;
+ }
outrel.r_offset = sec_addr (got) + off;
outrel.r_info = ELFNN_R_INFO (0, R_LARCH_RELATIVE);
@@ -2603,15 +2704,26 @@ loongarch_elf_relocate_section (bfd *output_bfd,
}
else
{
- LARCH_ASSERT (local_got_offsets, bfd_reloc_notsupported,
- "Internal: local got offsets not reporesent.");
-
- LARCH_ASSERT (local_got_offsets[r_symndx] != MINUS_ONE,
- bfd_reloc_notsupported,
- "Internal: GOT entry doesn't represent.");
+ if (!local_got_offsets)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "Internal: local got offsets not reporesent."));
+ break;
+ }
off = local_got_offsets[r_symndx] & (~1);
+ if (local_got_offsets[r_symndx] == MINUS_ONE)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "Internal: GOT entry doesn't represent."));
+ break;
+ }
+
/* The offset must always be a multiple of the word size.
So, we can use the least significant bit to record
whether we have already processed this entry. */
@@ -2625,8 +2737,14 @@ loongarch_elf_relocate_section (bfd *output_bfd,
/* We need to generate a R_LARCH_RELATIVE reloc
for the dynamic linker. */
s = htab->elf.srelgot;
- LARCH_ASSERT (s, bfd_reloc_notsupported,
- "Internal: '.rel.got' not represent");
+ if (!s)
+ {
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_notsupported, is_undefweak, name,
+ "Internal: '.rel.got' not represent"));
+ break;
+ }
outrel.r_offset = sec_addr (got) + off;
outrel.r_info = ELFNN_R_INFO (0, R_LARCH_RELATIVE);
@@ -2644,124 +2762,109 @@ loongarch_elf_relocate_section (bfd *output_bfd,
case R_LARCH_SOP_PUSH_TLS_GOT:
is_ie = TRUE;
case R_LARCH_SOP_PUSH_TLS_GD:
- unresolved_reloc = FALSE;
- LARCH_ASSERT (rel->r_addend == 0, bfd_reloc_notsupported,
- "Shouldn't be with r_addend.");
-
- if (resolved_to_const && is_undefweak && h->dynindx != -1)
- {
- /* What if undefweak? Let rtld make a decision. */
- resolved_to_const = resolved_local = FALSE;
- resolved_dynly = TRUE;
- }
-
- LARCH_ASSERT (!resolved_to_const, bfd_reloc_notsupported,
- "Internal: Shouldn't be resolved to const.");
-
- if (h != NULL)
- {
- off = h->got.offset;
- h->got.offset |= 1;
- }
- else
- {
- off = local_got_offsets[r_symndx];
- local_got_offsets[r_symndx] |= 1;
- }
-
- LARCH_ASSERT (off != MINUS_ONE, bfd_reloc_notsupported,
- "Internal: TLS GOT entry doesn't represent.");
-
- tls_type = _bfd_loongarch_elf_tls_type (input_bfd, h, r_symndx);
-
- /* If this symbol is referenced by both GD and IE TLS, the IE
- reference's GOT slot follows the GD reference's slots. */
- ie_off = 0;
- if ((tls_type & GOT_TLS_GD) && (tls_type & GOT_TLS_IE))
- ie_off = 2 * GOT_ENTRY_SIZE;
-
- if ((off & 1) != 0)
- off &= ~1;
- else
- {
- bfd_vma tls_block_off = 0;
- Elf_Internal_Rela outrel;
-
- if (resolved_local)
- {
- LARCH_ASSERT
- (elf_hash_table (info)->tls_sec, bfd_reloc_notsupported,
- "Internal: TLS sec not represent.");
- tls_block_off = relocation
- - elf_hash_table (info)->tls_sec->vma;
- }
-
- if (tls_type & GOT_TLS_GD)
- {
- outrel.r_offset = sec_addr (got) + off;
- outrel.r_addend = 0;
- bfd_put_NN (output_bfd, 0, got->contents + off);
- if (resolved_local && bfd_link_executable (info))
- /* a. 第一个被装载模块的Module ID为1。$glibc/elf/rtld.c中
- 的dl_main有一句'main_map->l_tls_modid = 1';
- b. 静态程序的Module ID不重要,但为了省事仍然是1。
- 详见$glibc/csu/libc-tls.c中的init_static_tls。 */
- bfd_put_NN (output_bfd, 1, got->contents + off);
- else if (resolved_local/* && !bfd_link_executable (info) */)
- {
- outrel.r_info = ELFNN_R_INFO (0, R_LARCH_TLS_DTPMODNN);
- loongarch_elf_append_rela
- (output_bfd, htab->elf.srelgot, &outrel);
- }
- else /* if (resolved_dynly) */
- {
- outrel.r_info =
- ELFNN_R_INFO (h->dynindx, R_LARCH_TLS_DTPMODNN);
- loongarch_elf_append_rela
- (output_bfd, htab->elf.srelgot, &outrel);
- }
+ {
+ unresolved_reloc = FALSE;
+ if (r_type == R_LARCH_SOP_PUSH_TLS_GOT)
+ is_ie = TRUE;
+
+ bfd_vma got_off = 0;
+ if (h != NULL)
+ {
+ got_off = h->got.offset;
+ h->got.offset |= 1;
+ }
+ else
+ {
+ got_off = local_got_offsets[r_symndx];
+ local_got_offsets[r_symndx] |= 1;
+ }
+
+ BFD_ASSERT (got_off != MINUS_ONE);
+
+ ie_off = 0;
+ tls_type = _bfd_loongarch_elf_tls_type (input_bfd, h, r_symndx);
+ if ((tls_type & GOT_TLS_GD) && (tls_type & GOT_TLS_IE))
+ ie_off = 2 * GOT_ENTRY_SIZE;
+
+ if ((got_off & 1) == 0)
+ {
+ Elf_Internal_Rela rela;
+ asection *srel = htab->elf.srelgot;
+ bfd_vma tls_block_off = 0;
+
+ if (SYMBOL_REFERENCES_LOCAL (info, h))
+ {
+ BFD_ASSERT (elf_hash_table (info)->tls_sec);
+ tls_block_off = relocation
+ - elf_hash_table (info)->tls_sec->vma;
+ }
- outrel.r_offset += GOT_ENTRY_SIZE;
- bfd_put_NN (output_bfd, tls_block_off,
- got->contents + off + GOT_ENTRY_SIZE);
- if (resolved_local)
- /* DTPREL known */;
- else /* if (resolved_dynly) */
- {
- outrel.r_info =
- ELFNN_R_INFO (h->dynindx, R_LARCH_TLS_DTPRELNN);
- loongarch_elf_append_rela
- (output_bfd, htab->elf.srelgot, &outrel);
- }
- }
+ if (tls_type & GOT_TLS_GD)
+ {
+ rela.r_offset = sec_addr (got) + got_off;
+ rela.r_addend = 0;
+ if (SYMBOL_REFERENCES_LOCAL (info, h))
+ {
+ /* Local sym, used in exec, set module id 1. */
+ if (bfd_link_executable (info))
+ bfd_put_NN (output_bfd, 1, got->contents + got_off);
+ else
+ {
+ rela.r_info = ELFNN_R_INFO (0,
+ R_LARCH_TLS_DTPMODNN);
+ loongarch_elf_append_rela (output_bfd, srel, &rela);
+ }
+
+ bfd_put_NN (output_bfd, tls_block_off,
+ got->contents + got_off + GOT_ENTRY_SIZE);
+ }
+ /* Dynamic resolved. */
+ else
+ {
+ /* Dynamic relocate module id. */
+ rela.r_info = ELFNN_R_INFO (h->dynindx,
+ R_LARCH_TLS_DTPMODNN);
+ loongarch_elf_append_rela (output_bfd, srel, &rela);
+
+ /* Dynamic relocate offset of block. */
+ rela.r_offset += GOT_ENTRY_SIZE;
+ rela.r_info = ELFNN_R_INFO (h->dynindx,
+ R_LARCH_TLS_DTPRELNN);
+ loongarch_elf_append_rela (output_bfd, srel, &rela);
+ }
+ }
+ if (tls_type & GOT_TLS_IE)
+ {
+ rela.r_offset = sec_addr (got) + got_off + ie_off;
+ if (SYMBOL_REFERENCES_LOCAL (info, h))
+ {
+ /* Local sym, used in exec, set module id 1. */
+ if (!bfd_link_executable (info))
+ {
+ rela.r_info = ELFNN_R_INFO (0, R_LARCH_TLS_TPRELNN);
+ rela.r_addend = tls_block_off;
+ loongarch_elf_append_rela (output_bfd, srel, &rela);
+ }
+
+ bfd_put_NN (output_bfd, tls_block_off,
+ got->contents + got_off + ie_off);
+ }
+ /* Dynamic resolved. */
+ else
+ {
+ /* Dynamic relocate offset of block. */
+ rela.r_info = ELFNN_R_INFO (h->dynindx,
+ R_LARCH_TLS_TPRELNN);
+ rela.r_addend = 0;
+ loongarch_elf_append_rela (output_bfd, srel, &rela);
+ }
+ }
+ }
- if (tls_type & GOT_TLS_IE)
- {
- outrel.r_offset = sec_addr (got) + off + ie_off;
- bfd_put_NN (output_bfd, tls_block_off,
- got->contents + off + ie_off);
- if (resolved_local && bfd_link_executable (info))
- /* TPREL known */;
- else if (resolved_local/* && !bfd_link_executable (info) */)
- {
- outrel.r_info = ELFNN_R_INFO (0, R_LARCH_TLS_TPRELNN);
- outrel.r_addend = tls_block_off;
- loongarch_elf_append_rela
- (output_bfd, htab->elf.srelgot, &outrel);
- }
- else /* if (resolved_dynly) */
- {
- outrel.r_info =
- ELFNN_R_INFO (h->dynindx, R_LARCH_TLS_TPRELNN);
- outrel.r_addend = 0;
- loongarch_elf_append_rela
- (output_bfd, htab->elf.srelgot, &outrel);
- }
- }
- }
- relocation = off + (is_ie ? ie_off : 0);
+ relocation = (got_off & (~(bfd_vma)1)) + (is_ie ? ie_off : 0);
+ }
break;
default:
@@ -2786,8 +2889,12 @@ loongarch_elf_relocate_section (bfd *output_bfd,
if (input_section->output_section->flags & SEC_DEBUGGING)
{
- LARCH_ASSERT (0, bfd_reloc_dangerous,
- "Seems dynamic linker not process sections 'SEC_DEBUGGING'.");
+ fatal = (loongarch_reloc_is_fatal
+ (info, input_bfd, input_section, rel, howto,
+ bfd_reloc_dangerous, is_undefweak, name,
+ "Seems dynamic linker not process "
+ "sections 'SEC_DEBUGGING'."));
+
break;
}
if (!is_dyn)
@@ -2798,7 +2905,6 @@ loongarch_elf_relocate_section (bfd *output_bfd,
info->flags |= DF_TEXTREL;
}
while (0);
-#undef LARCH_ASSERT
if (fatal)
break;
@@ -2997,7 +3103,6 @@ loongarch_elf_finish_dynamic_symbol (bfd *output_bfd,
}
else
{
- asection *plt;
/* For non-shared object, we can't use .got.plt, which
contains the real function address if we need pointer
equality. We load the GOT entry with the PLT entry. */
@@ -3447,15 +3552,17 @@ _loongarch_bfd_set_section_contents(bfd *abfd,
bfd_size_type conut)
{
- if (elf_elfheader(abfd)->e_flags ==0)
- if(abfd->arch_info->arch == bfd_arch_loongarch)
- if (abfd->arch_info->mach ==bfd_mach_loongarch32)
- elf_elfheader(abfd)->e_flags = EF_LARCH_ABI_LP32;
- else if (abfd->arch_info->mach ==bfd_mach_loongarch64)
- elf_elfheader(abfd)->e_flags = EF_LARCH_ABI_LP64;
- else
- return FALSE;
- return _bfd_elf_set_section_contents(abfd,section,location,offset,conut);
+ if (elf_elfheader(abfd)->e_flags == 0
+ && abfd->arch_info->arch == bfd_arch_loongarch)
+ {
+ if (abfd->arch_info->mach ==bfd_mach_loongarch32)
+ elf_elfheader(abfd)->e_flags = EF_LARCH_ABI_LP32;
+ else if (abfd->arch_info->mach ==bfd_mach_loongarch64)
+ elf_elfheader(abfd)->e_flags = EF_LARCH_ABI_LP64;
+ else
+ return FALSE;
+ }
+ return _bfd_elf_set_section_contents(abfd,section,location,offset,conut);
}
diff --git a/gas/config/loongarch-lex.l b/gas/config/loongarch-lex.l
index d88fc93a..55901dd6 100644
--- a/gas/config/loongarch-lex.l
+++ b/gas/config/loongarch-lex.l
@@ -2,6 +2,9 @@
%{
#include "as.h"
#include "loongarch-parse.h"
+/* Flex generates static functions "input" & "unput" which are not used. */
+#define YY_NO_INPUT
+#define YY_NO_UNPUT
%}
D [0-9]
diff --git a/gas/config/loongarch-parse.y b/gas/config/loongarch-parse.y
index aa7e51f5..51c862df 100644
--- a/gas/config/loongarch-parse.y
+++ b/gas/config/loongarch-parse.y
@@ -1,7 +1,7 @@
%{
#include "as.h"
#include "loongarch-parse.h"
-void yyerror(const char *s) {}
+static void yyerror(const char *s ATTRIBUTE_UNUSED) {}
extern int yylex (void);
extern void yy_scan_string (const char *);
extern void
@@ -25,6 +25,12 @@ is_const (struct reloc_info *info)
&& info->value.X_op == O_constant;
}
+int
+loongarch_parse_expr (const char *expr,
+ struct reloc_info *reloc_stack_top,
+ size_t max_reloc_num,
+ size_t *reloc_num,
+ offsetT *imm);
int
loongarch_parse_expr (const char *expr,
struct reloc_info *reloc_stack_top,
@@ -178,6 +184,7 @@ emit_unary (char op)
{
case '!':
top->type = BFD_RELOC_LARCH_SOP_NOT;
+ break;
default:
abort ();
}
diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index fbcc7c1f..b8bf3510 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -274,32 +274,6 @@ my_getExpression (expressionS *ep, const char *str)
return ret;
}
-
-/* for compitable with MIPS pesudo insn like '.set reorder'
- but actually ignore them. */
-static void
-s_loongarch_set (int x ATTRIBUTE_UNUSED)
-{
- char *name = input_line_pointer, ch;
-
- while (!is_end_of_line[(unsigned char) *input_line_pointer])
- ++input_line_pointer;
- ch = *input_line_pointer;
- *input_line_pointer = '\0';
-
- if (strchr (name, ','))
- {
- /* Generic ".set" directive; use the generic handler. */
- *input_line_pointer = ch;
- input_line_pointer = name;
- s_set (0);
- return;
- }
-
- *input_line_pointer = ch;
- demand_empty_rest_of_line ();
-}
-
static void
s_loongarch_align (int arg)
{
@@ -419,7 +393,7 @@ extern int loongarch_parse_expr (const char *expr,
size_t max_reloc_num, size_t *reloc_num,
offsetT *imm_if_no_reloc);
-int
+static int
is_internal_label (const char *c_str)
{
do
@@ -1026,6 +1000,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
case BFD_RELOC_LARCH_SOP_PUSH_TLS_GOT:
if (fixP->fx_addsy)
S_SET_THREAD_LOCAL (fixP->fx_addsy);
+ /* Fall through. */
case BFD_RELOC_LARCH_SOP_PUSH_PCREL:
case BFD_RELOC_LARCH_SOP_PUSH_PLT_PCREL:
if (fixP->fx_addsy == NULL)
@@ -1326,17 +1301,10 @@ loongarch_handle_align (fragS *fragp)
and use zeroes otherwise. */
gas_assert (excess < 4);
fragp->fr_fix += excess;
- switch (excess)
- {
- case 3:
- *p++ = '\0';
- case 2:
- *p++ = '\0';
- case 1:
- *p++ = '\0';
- case 0:
- break;
- }
+
+
+ while (excess-- != 0)
+ *p++ = 0;
md_number_to_chars (p, opcode, size);
fragp->fr_var = size;
diff --git a/opcodes/loongarch-dis.c b/opcodes/loongarch-dis.c
index 888c55f5..a159bb68 100644
--- a/opcodes/loongarch-dis.c
+++ b/opcodes/loongarch-dis.c
@@ -2,6 +2,7 @@
#include "disassemble.h"
#include "opintl.h"
#include "opcode/loongarch.h"
+#include "libiberty.h"
#include <stdlib.h>
static const struct loongarch_opcode *
@@ -78,7 +79,8 @@ parse_loongarch_dis_options (const char *opts_in)
if (opts_in == NULL)
return 0;
- char opts[strlen (opts_in) + 1], *opt, *opt_end;
+ char *opts, *opt, *opt_end;
+ opts = xmalloc (strlen (opts_in) + 1);
strcpy (opts, opts_in);
for (opt = opt_end = opts; opt_end != NULL; opt = opt_end + 1)
@@ -88,6 +90,7 @@ parse_loongarch_dis_options (const char *opts_in)
if (parse_loongarch_dis_option (opt) != 0)
return -1;
}
+ free (opts);
return 0;
}
@@ -215,13 +218,14 @@ disassemble_one (insn_t insn, struct disassemble_info *info)
info->fprintf_func (info->stream, "%s", opc->name);
{
- char fake_args[strlen (opc->format) + 1];
+ char *fake_args = xmalloc (strlen (opc->format) + 1);
const char *fake_arg_strs[MAX_ARG_NUM_PLUS_2];
strcpy (fake_args, opc->format);
if (0 < loongarch_split_args_by_comma (fake_args, fake_arg_strs))
info->fprintf_func (info->stream, "\t");
info->private_data = &insn;
loongarch_foreach_args (opc->format, fake_arg_strs, dis_one_arg, info);
+ free (fake_args);
}
if (info->insn_type == dis_branch || info->insn_type == dis_condbranch
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lixing-loongson-cn/binutils_anolis.git
git@gitee.com:lixing-loongson-cn/binutils_anolis.git
lixing-loongson-cn
binutils_anolis
binutils_anolis
a8

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385