Skip to content

Commit fc693b3

Browse files
committed
fix(util/grub-mkimagexx): unconditionaly use 64-bit addresses for mips64el-efi
grub_addr_t uses host pointer size, which becomes undesirable if the host architecture is 32-bit, e.g. for i486 and armhf/el. Also use the ULL suffix for 64-bit constants.
1 parent 739cf9f commit fc693b3

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

util/grub-mkimagexx.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,36 +1216,36 @@ SUFFIX (relocate_addrs) (Elf_Ehdr *e, struct section_metadata *smd,
12161216
case R_MIPS_26:
12171217
{
12181218
grub_uint32_t *t32 = (grub_uint32_t *) target;
1219-
grub_addr_t addr = grub_host_to_target64 (sym_addr);
1220-
*t32 = ((*t32) & 0xfc000000U) | ((addr >> 2) & 0x3ffffffUL);
1219+
grub_uint64_t addr = grub_host_to_target64 (sym_addr);
1220+
*t32 = ((*t32) & 0xfc000000U) | ((addr >> 2) & 0x3ffffffULL);
12211221
}
12221222
break;
12231223
case R_MIPS_LO16:
12241224
{
12251225
grub_int16_t *t16 = (grub_int16_t *) target;
1226-
grub_addr_t addr = grub_host_to_target64 (sym_addr);
1226+
grub_uint64_t addr = grub_host_to_target64 (sym_addr);
12271227
*t16 = (grub_int16_t) addr;
12281228
}
12291229
break;
12301230
case R_MIPS_HI16:
12311231
{
12321232
grub_int16_t *t16 = (grub_int16_t *) target;
1233-
grub_addr_t addr = grub_host_to_target64 (sym_addr);
1234-
*t16 = (grub_int16_t) ((addr + 0x8000UL) >> 16);
1233+
grub_uint64_t addr = grub_host_to_target64 (sym_addr);
1234+
*t16 = (grub_int16_t) ((addr + 0x8000ULL) >> 16);
12351235
}
12361236
break;
12371237
case R_MIPS_HIGHER:
12381238
{
12391239
grub_int16_t *t16 = (grub_int16_t *) target;
1240-
grub_addr_t addr = grub_host_to_target64 (sym_addr);
1241-
*t16 = (grub_int16_t) ((addr + 0x80008000UL) >> 32);
1240+
grub_uint64_t addr = grub_host_to_target64 (sym_addr);
1241+
*t16 = (grub_int16_t) ((addr + 0x80008000ULL) >> 32);
12421242
}
12431243
break;
12441244
case R_MIPS_HIGHEST:
12451245
{
12461246
grub_uint16_t *t16 = (grub_uint16_t *) target;
1247-
grub_addr_t addr = grub_host_to_target64 (sym_addr);
1248-
*t16 = (grub_uint16_t) ((addr + 0x800080008000UL) >> 48);
1247+
grub_uint64_t addr = grub_host_to_target64 (sym_addr);
1248+
*t16 = (grub_uint16_t) ((addr + 0x800080008000ULL) >> 48);
12491249
}
12501250
break;
12511251
default:
@@ -1901,19 +1901,19 @@ translate_relocation_pe (struct translate_context *ctx,
19011901
/* Hi */
19021902
ctx->current_address
19031903
= add_fixup_entry (&ctx->lst, 0,
1904-
(grub_int16_t) ((target & 0x8000UL) >> 16),
1904+
(grub_int16_t) ((target & 0x8000ULL) >> 16),
19051905
0, ctx->current_address,
19061906
image_target);
19071907
/* Higher */
19081908
ctx->current_address
19091909
= add_fixup_entry (&ctx->lst, 0,
1910-
(grub_int16_t) ((target & 0x80008000UL) >> 32),
1910+
(grub_int16_t) ((target & 0x80008000ULL) >> 32),
19111911
0, ctx->current_address,
19121912
image_target);
19131913
/* Highest */
19141914
ctx->current_address
19151915
= add_fixup_entry (&ctx->lst, 0,
1916-
(grub_uint16_t) ((target & 0x800080008000UL) >> 48),
1916+
(grub_uint16_t) ((target & 0x800080008000ULL) >> 48),
19171917
0, ctx->current_address,
19181918
image_target);
19191919
}
@@ -1936,13 +1936,13 @@ translate_relocation_pe (struct translate_context *ctx,
19361936
/* Higher */
19371937
ctx->current_address
19381938
= add_fixup_entry (&ctx->lst, 0,
1939-
(grub_int16_t) ((target & 0x80008000UL) >> 32),
1939+
(grub_int16_t) ((target & 0x80008000ULL) >> 32),
19401940
0, ctx->current_address,
19411941
image_target);
19421942
/* Highest */
19431943
ctx->current_address
19441944
= add_fixup_entry (&ctx->lst, 0,
1945-
(grub_uint16_t) ((target & 0x800080008000UL) >> 48),
1945+
(grub_uint16_t) ((target & 0x800080008000ULL) >> 48),
19461946
0, ctx->current_address,
19471947
image_target);
19481948
}
@@ -1965,13 +1965,13 @@ translate_relocation_pe (struct translate_context *ctx,
19651965
/* Hi */
19661966
ctx->current_address
19671967
= add_fixup_entry (&ctx->lst, 0,
1968-
(grub_int16_t) ((target & 0x8000UL) >> 16),
1968+
(grub_int16_t) ((target & 0x8000ULL) >> 16),
19691969
0, ctx->current_address,
19701970
image_target);
19711971
/* Highest */
19721972
ctx->current_address
19731973
= add_fixup_entry (&ctx->lst, 0,
1974-
(grub_uint16_t) ((target & 0x800080008000UL) >> 48),
1974+
(grub_uint16_t) ((target & 0x800080008000ULL) >> 48),
19751975
0, ctx->current_address,
19761976
image_target);
19771977
}
@@ -1994,13 +1994,13 @@ translate_relocation_pe (struct translate_context *ctx,
19941994
/* Hi */
19951995
ctx->current_address
19961996
= add_fixup_entry (&ctx->lst, 0,
1997-
(grub_int16_t) ((target & 0x8000UL) >> 16),
1997+
(grub_int16_t) ((target & 0x8000ULL) >> 16),
19981998
0, ctx->current_address,
19991999
image_target);
20002000
/* Higher */
20012001
ctx->current_address
20022002
= add_fixup_entry (&ctx->lst, 0,
2003-
(grub_int16_t) ((target & 0x80008000UL) >> 32),
2003+
(grub_int16_t) ((target & 0x80008000ULL) >> 32),
20042004
0, ctx->current_address,
20052005
image_target);
20062006
}

0 commit comments

Comments
 (0)