1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-10 10:57:55 +03:00

[ELF] Fix -Wtype-limits

These relocations are defined as follows

  R_SPARC_GOTDATA_OP_HIX22    (G >> 10) ^ (G >> 31)
  R_SPARC_GOTDATA_OP_LOX10    (G & 0x3ff) | ((G >> 31) & 0x1c00)

where G is an offset into .got. Since .got is much smaller than 4 GiB,
(G >> 31) is always zero, so we can ignore that part.

https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-24/index.html
This commit is contained in:
Rui Ueyama 2022-10-11 13:50:35 +08:00
parent 12ff7bb067
commit 0d368b44de

View File

@ -263,7 +263,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
// symbol is local, because R_SPARC_GOTDATA_OP cannot represent
// an addend for a local symbol.
if (sym.is_imported) {
*(ub32 *)loc |= bits(G < 0 ? ~G : G, 31, 10);
*(ub32 *)loc |= bits(G, 31, 10);
} else if (sym.is_absolute()) {
i64 val = S + A;
*(ub32 *)loc |= bits(val < 0 ? ~val : val, 31, 10);
@ -274,7 +274,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
break;
case R_SPARC_GOTDATA_OP_LOX10: {
if (sym.is_imported) {
*(ub32 *)loc |= bits(G, 9, 0) | (G < 0 ? 0b1'1100'0000'0000 : 0);
*(ub32 *)loc |= bits(G, 9, 0);
} else if (sym.is_absolute()) {
i64 val = S + A;
*(ub32 *)loc |= bits(val, 9, 0) | (val < 0 ? 0b1'1100'0000'0000 : 0);