Skip to content
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

Investigate code size for RISCV64 build vs AARCH64 #2

Closed
andreiw opened this issue Mar 22, 2023 · 4 comments
Closed

Investigate code size for RISCV64 build vs AARCH64 #2

andreiw opened this issue Mar 22, 2023 · 4 comments
Assignees

Comments

@andreiw
Copy link
Contributor

andreiw commented Mar 22, 2023

RISCV64 build is 2x the size of AARCH64 build, when build with comparable options.

The difference almost comes from the -Os compared to the aarch64 parts. The RISC-V parts will have an even smaller code size with the below options enabled.

  • -Os
  • -mrelax

Also, look into LTO.

@andreiw
Copy link
Contributor Author

andreiw commented Sep 16, 2023

5a9c89b

LTO support depends on edk2 support for LTO on RISCV

@andreiw andreiw closed this as completed Sep 16, 2023
@andreiw andreiw reopened this Sep 16, 2023
@andreiw
Copy link
Contributor Author

andreiw commented Sep 16, 2023

-mrelax may be dangerous since gp isn't loaded anywhere (UEFI
is built with -mno-relax). Worse, building with -Os
causes a regression with the CpuExitImage test.

Somehow the RaiseTPL from CpuExitImage call is getting corrupted.

FATAL ERROR - RaiseTpl with OldTpl(0x1F) > NewTpl(0x10)
ASSERT [DxeCore] /home/andreiw/src/edk2/MdeModulePkg/Core/Dxe/Event/Tpl.c(66): ((BOOLEAN)(0==1))

@andreiw andreiw self-assigned this Sep 16, 2023
@andreiw
Copy link
Contributor Author

andreiw commented Sep 19, 2023

Okay that assert is unrelated (it's caused by using a ConOut-based DebugLib with a high TPL, separate issue to file).

The real issue is due -Os implying -fomit-frame-pointer.

After calling CpuExitImage we hit a different assert with this backtrace:

#0 0x000000017e177d5e in RiscVCpuPause ()
#1 0x000000017e177ab4 in CpuDeadLoop () at /home/andreiw/src/edk2/MdePkg/Library/BaseLib/CpuDeadLoop.c:30
#2 0x000000017e11f8f0 in DebugAssert (FileName=FileName@entry=0x17e17a1a8 "/home/andreiw/src/edk2/MultiArchUefiPkg/Drivers/Emulator/Cpu.c",
LineNumber=LineNumber@entry=1242, Description=Description@entry=0x17e17a508 "Cpu->Contexts >= 0")
at /home/andreiw/src/edk2/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c:235
#3 0x000000017e11d770 in CpuDetectOrphanContexts (Context=0x17ed60198) at /home/andreiw/src/edk2/MultiArchUefiPkg/Drivers/Emulator/Cpu.c:1242
#4 CpuRunCtxOnPrivateStack (Context=Context@entry=0x17ed60198) at /home/andreiw/src/edk2/MultiArchUefiPkg/Drivers/Emulator/Cpu.c:1291
#5 0x000000017e11dbee in CpuRunCtx (Context=Context@entry=0x17ed60198) at /home/andreiw/src/edk2/MultiArchUefiPkg/Drivers/Emulator/Cpu.c:1366
#6 0x000000017e11dea6 in CpuRunImage (ImageHandle=0x17ed60e18, SystemTable=)
at /home/andreiw/src/edk2/MultiArchUefiPkg/Drivers/Emulator/Cpu.c:1517
#7 0x000000008333f910 in CoreStartImage (ImageHandle=0x17ed60e18, ExitDataSize=0x0, ExitData=0x0)
at /home/andreiw/src/edk2/MdeModulePkg/Core/Dxe/Image/Image.c:1702
#8 0x000000017e1b555a in InternalShellExecuteDevicePath (ParentImageHandle=0x17e2c8580 , DevicePath=0x17ed98018, CommandLine=0x17ed9b918,
Environment=0x0, StartImageStatus=0x83fff7f8) at /home/andreiw/src/edk2/ShellPkg/Application/Shell/ShellProtocol.c:1619
#9 0x000000017e1af714 in RunCommandOrFile (Type=Efi_Application, CmdLine=0x17ed9b918, FirstParameter=0x17ed98318, ParamProtocol=0x17ed9cf18,
CommandStatus=0x0) at /home/andreiw/src/edk2/ShellPkg/Application/Shell/Shell.c:2648
#10 0x000000017e1af808 in SetupAndRunCommandOrFile (Type=Efi_Application, CmdLine=0x17ed9b918, FirstParameter=0x17ed98318, ParamProtocol=0x17ed9cf18,
CommandStatus=0x0) at /home/andreiw/src/edk2/ShellPkg/Application/Shell/Shell.c:2733
#11 0x000000017e1afb46 in RunShellCommand (CmdLine=0x17ed71018, CommandStatus=0x0) at /home/andreiw/src/edk2/ShellPkg/Application/Shell/Shell.c:2858
#12 0x000000017e1afc3c in RunCommand (CmdLine=0x17ed71018) at /home/andreiw/src/edk2/ShellPkg/Application/Shell/Shell.c:2911
#13 0x000000017e1ada18 in DoShellPrompt () at /home/andreiw/src/edk2/ShellPkg/Application/Shell/Shell.c:1456
#14 0x000000017e1ac428 in UefiMain (ImageHandle=0x17f3de018, SystemTable=0x17fffe018) at /home/andreiw/src/edk2/ShellPkg/Application/Shell/Shell.c:651
#15 0x000000017e1ab10a in ProcessModuleEntryPointList (ImageHandle=0x17f3de018, SystemTable=0x17fffe018)
at /home/andreiw/src/edk2/Build/RiscVVirtQemu/DEBUG_GCC5/RISCV64/ShellPkg/Application/Shell/Shell/DEBUG/AutoGen.c:1148
#16 0x000000017e1aa298 in _ModuleEntryPoint (ImageHandle=0x17f3de018, SystemTable=0x17fffe018)
at /home/andreiw/src/edk2/MdePkg/Library/UefiApplicationEntryPoint/ApplicationEntryPoint.c:58
#17 0x000000008333f910 in CoreStartImage (ImageHandle=0x17f3de018, ExitDataSize=0x17ef0bc98, ExitData=0x17ef0bc90)
at /home/andreiw/src/edk2/MdeModulePkg/Core/Dxe/Image/Image.c:1702
#18 0x000000017fcec90a in EfiBootManagerBoot (BootOption=0x17ef0bc48) at /home/andreiw/src/edk2/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c:2039
#19 0x000000017fcde0fe in BootBootOptions (BootOptions=0x17ef0bb98, BootOptionCount=3, BootManagerMenu=0x83fffc08)
at /home/andreiw/src/edk2/MdeModulePkg/Universal/BdsDxe/BdsEntry.c:414
#20 0x000000017fcdf46a in BdsEntry (This=0x17fd05f88 ) at /home/andreiw/src/edk2/MdeModulePkg/Universal/BdsDxe/BdsEntry.c:1094
#21 0x000000008333b5d8 in DxeMain (HobStart=0x17fa53018) at /home/andreiw/src/edk2/MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c:575
#22 0x000000008333a6a2 in ProcessModuleEntryPointList (HobStart=0x82000000)
at /home/andreiw/src/edk2/Build/RiscVVirtQemu/DEBUG_GCC5/RISCV64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/AutoGen.c:590
#23 0x000000008333a266 in _ModuleEntryPoint (HobStart=0x82000000) at /home/andreiw/src/edk2/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.c:46
#24 0x00000000200062f0 in ?? ()

...so basically SetJmp returns 0 after the LongJump in CpuExitImage, and we don't exit, but try to run. This is because LongJumpInternal implementation is broken and it just so happens that with -Os x8 is mostly 0 (at that point).

See for fix andreiw/edk2-rv-wip@56871e7.
Meanwhile 06753ee builds with -Os and -fno-omit-frame-pointer for now.

Keeping this open...

@andreiw
Copy link
Contributor Author

andreiw commented Dec 9, 2023

Fix has been upstreamed.

@andreiw andreiw closed this as completed Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant