From b19aeeb91e3c548a7f42828f4d474e23ae6b59b8 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Sun, 10 Sep 2017 00:23:42 +0200 Subject: [PATCH] MdeModulePkg/PartitionDxe: don't divide 64-bit values with C operators In edk2, the division and shifting of 64-bit values are forbidden with C-language operators, because the compiler may generate intrinsic calls for them. For example, clang-3.8 emits a call to "__umoddi3" for UDF_LOGICAL_SECTOR_SIZE % Media->BlockSize in PartitionInstallUdfChildHandles(), if PartitionDxe is built for IA32, which then fails to link. UDF_LOGICAL_SECTOR_SIZE has type UINT64, while EFI_BLOCK_IO_MEDIA.BlockSize has type UINT32(). Replace the % operator with a DivU64x32Remainder() call. Cc: Ard Biesheuvel Cc: Eric Dong Cc: Paulo Alcantara Cc: Ruiyu Ni Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Ruiyu Ni Reviewed-by: Star Zeng Reviewed-by: Paulo Alcantara Reviewed-by: Ard Biesheuvel --- MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c index 3174ab2b4b..e46cf1d4f4 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c @@ -243,6 +243,7 @@ PartitionInstallUdfChildHandles ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { + UINT32 RemainderByMediaBlockSize; EFI_STATUS Status; EFI_BLOCK_IO_MEDIA *Media; EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; @@ -255,7 +256,12 @@ PartitionInstallUdfChildHandles ( // // Check if UDF logical block size is multiple of underlying device block size // - if ((UDF_LOGICAL_SECTOR_SIZE % Media->BlockSize) != 0 || + DivU64x32Remainder ( + UDF_LOGICAL_SECTOR_SIZE, // Dividend + Media->BlockSize, // Divisor + &RemainderByMediaBlockSize // Remainder + ); + if (RemainderByMediaBlockSize != 0 || Media->BlockSize > UDF_LOGICAL_SECTOR_SIZE) { return EFI_NOT_FOUND; }