All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: Jan Beulich <jbeulich@suse.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Julien Grall" <julien@xen.org>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Anthony PERARD" <anthony.perard@vates.tech>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Roger Pau Monné" <roger@xenproject.org>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Connor Davis" <connojdavis@gmail.com>
Subject: Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
Date: Thu, 27 Aug 2026 17:40:39 +0200	[thread overview]
Message-ID: <0d0c6a5b-94a5-49c6-a150-3bb6a0dc3b93@gmail.com> (raw)
In-Reply-To: <f26f80e3-0b2d-429a-895c-b8003d1c5a38@suse.com>



On 8/26/26 2:04 PM, Jan Beulich wrote:
> Of the short-data sections, only .sbss is presently mentioned in the
> linker script. Place them next to, but ahead of their "normal" data
> sections.
> 
> .riscv.attributes can go towards the tail of the image, next to (ahead of)
> debug info.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> Seeing where .sbss lives, does positioning really not matter at all? I
> would have expected that short-data sections want to live close together,
> and specifically close to .text / .init.text (seeing that such data is
> accessed using AUIPC). I'm puzzled that the psABI doesn't even mention
> them, hence leaving it open how exactly they are to be used.

It doesn't, and the reason is that the relevant proximity isn't to .text 
but to __global_pointer$. The small-data sections exist to let a linker 
script cluster small objects around that anchor so that ld's relaxation 
pass can fold an auipc+load pair into a single gp-relative access (-+2 
KiB window).

That pass is keyed purely on the symbol being defined 
riscv_global_pointer_value() returns 0 otherwise and the relaxation is 
skipped. We define no __global_pointer$ and head.S never loads gp (it 
appears only as a cpu_user_regs slot in entry.S), so every access stays 
the medany auipc form regardless of section.

I confirmed this by linking the same object twice (look at the script 
below, with and without the symbol: without it, zero gp-relative 
accesses; with it, the pairs collapse.

Worth noting the relaxation is section-agnostic: in the test mentioned 
below a 400-byte array in plain .bss got gp-relative too, purely because 
it landed in range. So the sections are a clustering hint, not a 
mechanism ld keys off.

The script I used:
```
mkdir -p /tmp/gp-demo && cd /tmp/gp-demo

# 1. Test code: one small variable (-> .sbss) and one large array (-> .bss)
cat > s.c <<'EOF'
int small_var;                                  /* 4 bytes   -> .sbss */
int big_arr[100];                               /* 400 bytes -> .bss  */
int read_small(void) { return small_var; }
int read_big(void)   { return big_arr[0]; }
EOF

# 2. Linker script WITHOUT __global_pointer$
cat > nogp.lds <<'EOF'
ENTRY(read_small)
SECTIONS {
   . = 0xffffffffc0000000;
   .text : { *(.text) *(.text.*) }
   .data : { *(.sdata .sdata.*) *(.data .data.*) }
   .bss  : { *(.sbss .sbss.*) *(.bss .bss.*) *(COMMON) }
   /DISCARD/ : { *(.comment) *(.note*) *(.riscv.attributes) }
}
EOF

# 3. Same script, but WITH __global_pointer$ defined
sed 's|^  \.data : {|  __global_pointer$ = . + 0x800;\n  .data : {|' 
nogp.lds > gp.lds

riscv64-linux-gnu-gcc -O2 -march=rv64ima -mabi=lp64 -mcmodel=medany \
                       -ffreestanding -c s.c -o s.o

# Check the INPUT sections: .sbss vs plain .bss (the link merges them, so
# inspect s.o, not the linked ELF)
echo "### INPUT sections the symbols live in ###"
riscv64-linux-gnu-objdump -t s.o | grep -E 'small_var|big_arr'

# Link both ways and compare the generated code
for L in nogp gp; do
   riscv64-linux-gnu-ld -T $L.lds s.o -o $L.elf 2>/dev/null
   echo "=============== $L.lds ==============="
   riscv64-linux-gnu-objdump -d --no-show-raw-insn $L.elf \
     | sed -n '/<read_small>:/,/ret/p;/<read_big>:/,/ret/p'
done

```


> 
> What remains to eliminate orphan section warnings is the placement of
> .note.GNU-stack (which perhaps wants dealing with on all of Arm, PPC, and
> RISC-V together, ideally unifying with x86) and (odd at the first glance,
> but dealt with on x86 as well, i.e. may again want unifying) that of a
> number of .rela.* sections.
> 
> --- a/xen/arch/riscv/xen.lds.S
> +++ b/xen/arch/riscv/xen.lds.S
> @@ -44,6 +44,8 @@ SECTIONS
>   
>           BUGFRAMES
>   
> +        *(.srodata)
> +        *(.srodata.*)
>           *(.rodata)
>           *(.rodata.*)
>           VPCI_ARRAY
> @@ -92,6 +94,7 @@ SECTIONS
>           SCHEDULER_ARRAY
>           HYPFS_PARAM
>   
> +        *(.sdata .sdata.*)
>           *(.data .data.*)
>           CONSTRUCTORS
>       } :text
> @@ -162,6 +165,8 @@ SECTIONS
>       /* Section for the device tree blob (if any). */
>       .dtb : { *(.dtb) } :text
>   
> +    .riscv.attributes : { *(.riscv.attributes) } :text
> +

Nit: .riscv.attributes is SHT_RISCV_ATTRIBUTES, i.e. non-alloc.
:text on it is misleading, and without an explicit address it gets 
sh_addr from .(location counter) after .dtb. Could we use matching the 
idiom used for every other non-alloc section in xen.lds.h:
   .riscv.attributes 0 : { *(.riscv.attributes) }
No functional difference either way (objcopy -O binary drops it, and I 
verified a non-alloc output section doesn't advance dot, so nothing 
downstream shifts), so purely consistency.

Is dropping orphan-handling-y := from arch/riscv/Makefile the intended 
end of this series? As if I understand correctly with such defintion we 
will miss warning so everything of that will be missed:

cd xen
riscv64-linux-gnu-ld -T arch/riscv/xen.lds prelink.o 
--orphan-handling=warn -o /tmp/t.elf 2>&1 \
   | grep 'orphan section'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.note.GNU-stack' 
from `prelink.o' being placed in section `.note.GNU-stack'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.text' from 
`prelink.o' being placed in section `.rela.dyn'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.text' 
from `prelink.o' being placed in section `.rela.dyn'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section 
`.rela.data.read_mostly' from `prelink.o' being placed in section 
`.rela.dyn'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.data' 
from `prelink.o' being placed in section `.rela.dyn'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section 
`.rela.text.header' from `prelink.o' being placed in section `.rela.dyn'

Thanks.

~ Oleksii


  reply	other threads:[~2026-08-27 15:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
2026-08-26 12:00 ` [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules Jan Beulich
2026-09-02 14:52   ` Anthony PERARD
2026-09-03  7:26     ` Jan Beulich
2026-08-26 12:00 ` [PATCH v2 2/7] Arm: split xen-syms linking rule Jan Beulich
2026-09-02 16:32   ` Anthony PERARD
2026-09-03  7:35     ` Jan Beulich
2026-08-26 12:01 ` [PATCH v2 3/7] RISC-V: " Jan Beulich
2026-08-27 15:56   ` Oleksii Kurochko
2026-08-27 16:01     ` Jan Beulich
2026-08-27 16:12       ` Oleksii Kurochko
2026-08-26 12:01 ` [PATCH v2 4/7] PPC: " Jan Beulich
2026-09-03 11:50   ` Anthony PERARD
2026-08-26 12:02 ` [PATCH v2 5/7] build: move $(all-symbols-*) Jan Beulich
2026-09-03 11:54   ` Anthony PERARD
2026-08-26 12:03 ` [PATCH v2 6/7] build: move $(compare-symbol-tables) Jan Beulich
2026-09-03 11:55   ` Anthony PERARD
2026-08-26 12:04 ` [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes Jan Beulich
2026-08-27 15:40   ` Oleksii Kurochko [this message]
2026-08-27 15:53     ` Andrew Cooper
2026-08-27 15:56     ` Jan Beulich
2026-08-27 16:07       ` Oleksii Kurochko
2026-09-01  7:52         ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0d0c6a5b-94a5-49c6-a150-3bb6a0dc3b93@gmail.com \
    --to=oleksii.kurochko@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=connojdavis@gmail.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger@xenproject.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.