using the bpf target, the sim testsuite fails now due to linker warnings ever since this change: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=ba951afb99912da01a6e8434126b8fac7aa75107 Author: Nick Clifton <nickc@redhat.com> Date: Tue May 3 11:42:24 2022 +0100 Add a linker warning when creating potentially dangerous executable segments. Add tests, options to disabke and configure switches to choose defaults. simple test: $ cat test.s .bss .space 64 _stack: .data pass: .string "pass\n" .text .global _start _start: .byte 0x00 $ ./gas/as-new test.s -o test.o $ ./ld/ld-new test.o -Ttext=0x0 -o test ./ld/ld-new: warning: test has a LOAD segment with RWX permissions i know the use of -Ttext=0 is a bit odd, but it's what the bpf sim testsuite is doing. i'll leave it to Jose to figure out what the right approach is here.
Hi Jose, In case it helps I have proposed a patch for a similar problem for the MN10300 sim: https://sourceware.org/bugzilla/attachment.cgi?id=14546&action=edit Cheers Nick
Hi Nick. I tried that locally and definitely works. But I don't think it is the right fix in this case. When linked without -Ttext=0x0, the following segments are created in the resulting executable: Elf file type is EXEC (Executable file) Entry point 0x400000 There are 2 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000100000 0x0000000000400000 0x0000000000400000 0x0000000000000648 0x0000000000000648 R E 0x100000 LOAD 0x0000000000101648 0x0000000000801648 0x0000000000801648 0x0000000000000006 0x0000000000000006 RW 0x100000 Section to Segment mapping: Segment Sections... 00 .text 01 .data Which is perfectly fine. But then it is the simulator that fails with: spawn ./bpf/run --memory-size=4Mb /home/jemarch/gnu/src/binutils-gdb/build-bpf/sim/alu.s.x core: 8 byte read to unmapped address 0x400000 at 0x400000 Meaning the simulator is somehow not loading the segments at the right VMA.
(In reply to Jose E. Marchesi from comment #2) > Hi Nick. > > I tried that locally and definitely works. But I don't think it is the > right fix in this case. > > When linked without -Ttext=0x0, the following segments are created in the > resulting executable: > > Elf file type is EXEC (Executable file) > > Entry point 0x400000 > > There are 2 program headers, starting at offset 64 > > > > Program Headers: > > Type Offset VirtAddr PhysAddr > > FileSiz MemSiz Flags Align > > LOAD 0x0000000000100000 0x0000000000400000 0x0000000000400000 > > 0x0000000000000648 0x0000000000000648 R E 0x100000 > > LOAD 0x0000000000101648 0x0000000000801648 0x0000000000801648 > > 0x0000000000000006 0x0000000000000006 RW 0x100000 > > > > Section to Segment mapping: > > Segment Sections... > > 00 .text > > 01 .data > > > Which is perfectly fine. But then it is the simulator that fails with: > > spawn ./bpf/run --memory-size=4Mb > /home/jemarch/gnu/src/binutils-gdb/build-bpf/sim/alu.s.x > core: 8 byte read to unmapped address 0x400000 at 0x400000 > > Meaning the simulator is somehow not loading the segments at the right VMA. Increasing `--memory-size' in the simulator from 4Mb to 10MB SIGSEGV is gone, because .data start at address: 0x801648, Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000100000 0x0000000000400000 0x0000000000400000 0x0000000000000648 0x0000000000000648 R E 0x100000 LOAD 0x0000000000101648 0x0000000000801648 0x0000000000801648 0x0000000000000006 0x0000000000000006 RW 0x100000
merged Guillermo's change to increase the sim memory size & drop the -T flag