-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bl2 hang on mt7981 with BOOT_DEVICE=emmc (clang vs gcc) #8
Comments
A bit of INFO() debugging implies it locks up in
and then
gives Built with gcc, For completeness, the hang happens when bl2 is compiled with clang and linked with binutils ld, but doesn't happen when bl2 is compiled with gcc and linked with lld, so the choice of compiler is significant and the choice of linker is not. |
Ah, I'm an idiot - it's staring me in the face. diff --git a/drivers/partition/partition.c b/drivers/partition/partition.c
index 1436ddd3..6913d8bd 100644
--- a/drivers/partition/partition.c
+++ b/drivers/partition/partition.c
@@ -56,7 +56,7 @@ static int load_mbr_header(uintptr_t image_handle, mbr_entry_t *mbr_entry)
{
size_t bytes_read;
int result;
- mbr_entry_t *tmp;
+ mbr_entry_t tmp;
assert(mbr_entry != NULL);
/* MBR partition table is in LBA0. */
@@ -81,19 +81,19 @@ static int load_mbr_header(uintptr_t image_handle, mbr_entry_t *mbr_entry)
return -ENOENT;
}
- tmp = (mbr_entry_t *)(&mbr_sector[MBR_PRIMARY_ENTRY_OFFSET]);
+ memcpy(&tmp, mbr_sector + MBR_PRIMARY_ENTRY_OFFSET, sizeof tmp);
- if (tmp->first_lba != 1) {
+ if (tmp.first_lba != 1) {
VERBOSE("MBR header may have an invalid first LBA\n");
return -EINVAL;
}
- if ((tmp->sector_nums == 0) || (tmp->sector_nums == UINT32_MAX)) {
+ if ((tmp.sector_nums == 0) || (tmp.sector_nums == UINT32_MAX)) {
VERBOSE("MBR header entry has an invalid number of sectors\n");
return -EINVAL;
}
- memcpy(mbr_entry, tmp, sizeof(mbr_entry_t));
+ memcpy(mbr_entry, &tmp, sizeof(mbr_entry_t));
return 0;
}
fixes it and it boots normally. Presumably gcc's -mstrict-align papers over this UB whereas clang's doesn't. |
The bug fix is now in upstream ARM trusted-firmware-a: |
I spotted something interesting while compiling a bootloader and trusted-firmware for an mt7981 device, but haven't been able to debug it yet. I'll have a go at digging into it over the weekend if I get a chance.
Like ARM upstream, mtk-openwrt atf's Makefile includes support for building with clang as well as gcc.
bl31 + u-boot work fine when built with clang, as does bl2 with
BOOT_DEVICE=ram RAM_BOOT_UART_DL=1
. However, built with clang andBOOT_DEVICE=emmc
, bl2 hangs just before locating the fip partition:Built with gcc instead, it continues normally:
My exact build command for reproduction purposes is
where
CC
is either clang 18.1.5 or gcc aarch64 14.1.0, and LD is set to ld.lld or ld to match.The text was updated successfully, but these errors were encountered: