riscv-software-src / opensbi

RISC-V Open Source Supervisor Binary Interface
Other
985 stars 495 forks source link

understanding -PIE #369

Open tswaehn opened 3 weeks ago

tswaehn commented 3 weeks ago

just want to understand why -PIE is hard coded.

if a bare metal build should be created, then this option prevents it.

thus shouldnt the -PIE option be optional?

hints:

currently I always have to apply this patch: https://github.com/riscv-software-src/opensbi/commit/2fe7528c81453a713c6b946551e2d6f08df2d2d6

SiFiveHolland commented 3 weeks ago

The OpenSBI firmware binary is no less bare metal because it is a PIE. OpenSBI applies relocations to itself as part of its entry assembly code, so there is no external dependency to load the firmware.

What problems do you experience when you don't patch OpenSBI?

tswaehn commented 3 weeks ago

What problems do you experience when you don't patch OpenSBI?

Actually my toolchain does not support PIE. I should figure out how to rebuild with PIE if needed. That would be ok.

I appreciate the self relocation and I am a fan of flexibility. Just wondering if optional use of PIE (depending of toolchain capabilities) would be an option.

For me there is two options fork and patch or find I way to achieve both in the main repo, without need to fork - which is my preferred option. Thats why I am trying to understand if PIE could be optional.

(actually this is what I am doing)

tswaehn commented 2 weeks ago

@SiFiveHolland Just wondering, if we could make the PIE option optional. So we could avoid forking the repo, as mentioned here.

mikey commented 2 weeks ago

I think you just want to submit a patch to opensbi to make PIE an option, or even detect what the toolchain supports. The compile will need to specify FW_TEXT_START (or you could have a default of 0x80000000, like opensbi used to have)

SiFiveHolland commented 1 week ago

Were you unable to update your toolchain to support PIE? OpenSBI is not the only firmware to be compiled as a PIE. For example, U-Boot is as well. This seems to be a deficiency in your toolchain.

tswaehn commented 1 week ago

I am using the standard toolchain of Zephyr OS. Same actually goes for all my other toolchains. Usually I don't need PIE.

And actually the question is why should I enable PIE un the tool chain, although I don't need it. Additionally why is there the requirement to build openSBI with PIE although it seems to me there is no actual technical reason that really forces it. Instead it looks to me like it's optional - so why not making it optional then?

If ok, I will prepare a PR for qemu builds without PIE option, where for other targets PIE will be enabled.

Would that be acceptable?

Side note, it would be a huge benefit, if openSBI could be built out-of-the-box for Zephyr. Because actually we want to use openSBI as per-se default for machine mode software and introduce supervisor mode based on that.