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

Stop using linker-script for tests #462

Closed
wants to merge 1 commit into from

Conversation

dimitry-
Copy link

@dimitry- dimitry- commented Mar 2, 2023

My understating is that it can be replaced with -Wl,-Ttext to produce the same result. It also avoids leaving headers out of PT_LOAD segment as well as having RWE flag for one of the segments.

Copy link
Collaborator

@aswaterman aswaterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks RV64 tests on my system. And I'd actually prefer to keep the linker script, because the additional dependence on the toolchain's built-in linker script is another thing that can break across toolchain upgrades.

$ make rv64ui-p-add.out
riscv64-unknown-elf-gcc -march=rv64g -mabi=lp64 -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -I./../env/p -I./macros/scalar -Wl,-Ttext=0x80000000 rv64ui/add.S -o rv64ui-p-add
spike --isa=rv64gc_zfh_zicboz_svnapot --misaligned rv64ui-p-add 2> rv64ui-p-add.out
make: *** [Makefile:53: rv64ui-p-add.out] Error 255

$ cat rv64ui-p-add.out
Access exception occurred while loading payload rv64ui-p-add:
Memory address 0x7ffff000 is invalid

$ riscv64-unknown-elf-readelf -Wl rv64ui-p-add

Elf file type is EXEC (Executable file)
Entry point 0x80000000
There are 2 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x000000 0x000000007ffff000 0x000000007ffff000 0x0016bc 0x0016bc R E 0x1000
  LOAD           0x0016c0 0x00000000800016c0 0x00000000800016c0 0x000048 0x000048 RW  0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .text 
   01     .tohost

@dimitry-
Copy link
Author

dimitry- commented Mar 3, 2023

Memory address 0x7ffff000 is invalid

I think I need some education here - why is this address invalid?

@dimitry-
Copy link
Author

dimitry- commented Mar 3, 2023

To elaborate a little bit on reasons for the change. Some platforms will likely require better security practices and prohibit rwe mappings. And unfortunately using linker script together with ld.bfd produces such segments. Another reason is that program headers are being left out of load segment and this is unusual (I have another PR to fix this in linker scripts here: riscv/riscv-test-env#41).

@aswaterman
Copy link
Collaborator

I think I need some education here - why is this address invalid?

There's nothing fundamentally wrong with that address. But the default Spike memory map has memory at 0x80000000 and above, which is why the linker script does what it does.

@aswaterman
Copy link
Collaborator

To elaborate a little bit on reasons for the change. Some platforms will likely require better security practices and prohibit rwe mappings. And unfortunately using linker script together with ld.bfd produces such segments. Another reason is that program headers are being left out of load segment and this is unusual (I have another PR to fix this in linker scripts here: riscv/riscv-test-env#41).

I agree RWX mappings are a poor security practice, but these aren't normal programs; they're ISA test cases. They're supposed to run on the bare metal. So, while I agree with your general comment, I don't agree that it applies here.

@aswaterman aswaterman closed this Mar 3, 2023
@dimitry-
Copy link
Author

dimitry- commented Mar 3, 2023

Running isa cases on bare metal is not the only use-case, we are planning to run them on the emulator. As for LOAD address issue - it is addressed here: dimitry-@8c0203a, Unfortunately it no longer visible in this pull request since it is closed.

@aswaterman
Copy link
Collaborator

The tests are already written in such a way that you can build and run them in different environments. You can already use the existing source code and use a different Makefile/linker script/whatever. I don't think that there is a problem that needs to be solved.

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

Successfully merging this pull request may close these issues.

2 participants