Skip to contentSkip to conversation

xen.efi has MEM_DISCARDABLE flag in Characteristics field of .reloc section

DISCUSSION Demi Marie Obenour 3 participants 6 messages Jul 17, 2025

lore
Share & tools
lore
#1 lore raw
Quoted 8 lines · Demi Marie Obenour

This was discovered by GitHub user @fallen and leads to an "Unsupported relocation type" crash during boot because shim and some patched versions of GRUB do not load the section. See
https://github.com/QubesOS/qubes-issues/issues/8206#issuecomment-3078795967
for more details.

I'm not sure if this is a bug in Xen or a bug in the linker.

As said on Matrix, my take is that - if at all - the linker could do something about it only with a to-be-added command line option. For all "normal" purposes .reloc being discardable is what is wanted. Since such a command line option would be extremely niche, I think this will need taking care of on the Xen side (which, however, is unlikely to end up very pretty).

Jan

#2 lore raw

Hello Demi Marie, Jan, Nick, all,

Thank you Demi Marie for bringing this topic on the mailing list.

I discussed it a bit with Jan on Matrix but the situation is not pretty, there is no clean solution that stands out easily.

As Jan said, it seems .reloc is meant to be discardable, so we can't blame binutils LD for putting it:

https://github.com/bminor/binutils-gdb/commit/25c80428af3311e761c87d8f706596b9701602ec#diff-078cf751467928c038996b40073a682425712b9b01182424e68cf18fb08a75b5R953-R977

And we can't obviously blame the loaders for honoring this flag.

Most reasonable solution indeed would be to ask binutils to add a link flag to say "please do not put the DISCARDABLE flag on the .reloc section"

I'm adding Nick Clifton from binutils in CC so that he can comment on this possible outcome or any other possible solution.

In the mean time, while waiting for a solution to emerge (and be merged, and released) what do we do?

Do we put some hack in Xen build Makefiles so that xen.efi is post-processed to strip this bit?

This could be the temporary solution.

Regards,

Yann

Quoted 8 lines · Jan Beulich
Quoted 7 lines · Demi Marie Obenour

This was discovered by GitHub user @fallen and leads to an "Unsupported relocation type" crash during boot because shim and some patched versions of GRUB do not load the section. See
https://github.com/QubesOS/qubes-issues/issues/8206#issuecomment-3078795967
for more details.

Quoted 9 lines
Quoted 1 line

I'm not sure if this is a bug in Xen or a bug in the linker.

As said on Matrix, my take is that - if at all - the linker could do something about it only with a to-be-added command line option. For all "normal" purposes .reloc being discardable is what is wanted. Since such a command line option would be extremely niche, I think this will need taking care of on the Xen side (which, however, is unlikely to end up very pretty).

Jan

Yann Sionneau | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#3 lore raw
Quoted 20 lines · Yann Sionneau

Hello Demi Marie, Jan, Nick, all,

Thank you Demi Marie for bringing this topic on the mailing list.

I discussed it a bit with Jan on Matrix but the situation is not pretty, there is no clean solution that stands out easily.

As Jan said, it seems .reloc is meant to be discardable, so we can't blame binutils LD for putting it:

https://github.com/bminor/binutils-gdb/commit/25c80428af3311e761c87d8f706596b9701602ec#diff-078cf751467928c038996b40073a682425712b9b01182424e68cf18fb08a75b5R953-R977

And we can't obviously blame the loaders for honoring this flag.

Most reasonable solution indeed would be to ask binutils to add a link flag to say "please do not put the DISCARDABLE flag on the .reloc section"

I'm adding Nick Clifton from binutils in CC so that he can comment on this possible outcome or any other possible solution.

Quoted 7 lines

In the mean time, while waiting for a solution to emerge (and be merged, and released) what do we do?

Do we put some hack in Xen build Makefiles so that xen.efi is post-processed to strip this bit?

This could be the temporary solution.

As indicated - I don't think this is just a temporary solution. Beyond Xen, I simply don't see value in adding a linker flag (which then, sooner or later, llvm would also need to support just for Xen). The question rather is how to make the Xen side hack as little hacky as possible, without relying on the fragile behavior of objcopy.

Jan

#4 lore raw
Quoted 29 lines · Jan Beulich
Quoted 20 lines · Yann Sionneau

Hello Demi Marie, Jan, Nick, all,

Thank you Demi Marie for bringing this topic on the mailing list.

I discussed it a bit with Jan on Matrix but the situation is not pretty, there is no clean solution that stands out easily.

As Jan said, it seems .reloc is meant to be discardable, so we can't blame binutils LD for putting it:

https://github.com/bminor/binutils-gdb/commit/25c80428af3311e761c87d8f706596b9701602ec#diff-078cf751467928c038996b40073a682425712b9b01182424e68cf18fb08a75b5R953-R977

And we can't obviously blame the loaders for honoring this flag.

Most reasonable solution indeed would be to ask binutils to add a link flag to say "please do not put the DISCARDABLE flag on the .reloc section"

I'm adding Nick Clifton from binutils in CC so that he can comment on this possible outcome or any other possible solution.

Quoted 7 lines

In the mean time, while waiting for a solution to emerge (and be merged, and released) what do we do?

Do we put some hack in Xen build Makefiles so that xen.efi is post-processed to strip this bit?

This could be the temporary solution.

Quoted 8 lines

As indicated - I don't think this is just a temporary solution. Beyond Xen, I simply don't see value in adding a linker flag (which then, sooner or later, llvm would also need to support just for Xen). The question rather is how to make the Xen side hack as little hacky as possible, without relying on the fragile behavior of objcopy.

Jan

Ok I didn't understand your previous answer, it's more clear now, thank you. Would you consider using a tool like this less fragile than objcopy:
https://github.com/fallen/keeprelocs ?

Regards,

PS: sorry for earlier top posting, my Thunderbird was badly configured (new computer).

Signature · 8 lines
Yann


Yann Sionneau | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#5 lore raw
Quoted 36 lines · Yann Sionneau
Quoted 27 lines · Jan Beulich
Quoted 26 lines · Yann Sionneau

Hello Demi Marie, Jan, Nick, all,

Thank you Demi Marie for bringing this topic on the mailing list.

I discussed it a bit with Jan on Matrix but the situation is not pretty, there is no clean solution that stands out easily.

As Jan said, it seems .reloc is meant to be discardable, so we can't blame binutils LD for putting it:

https://github.com/bminor/binutils-gdb/commit/25c80428af3311e761c87d8f706596b9701602ec#diff-078cf751467928c038996b40073a682425712b9b01182424e68cf18fb08a75b5R953-R977

And we can't obviously blame the loaders for honoring this flag.

Most reasonable solution indeed would be to ask binutils to add a link flag to say "please do not put the DISCARDABLE flag on the .reloc section"

I'm adding Nick Clifton from binutils in CC so that he can comment on this possible outcome or any other possible solution.

In the mean time, while waiting for a solution to emerge (and be merged, and released) what do we do?

Do we put some hack in Xen build Makefiles so that xen.efi is post-processed to strip this bit?

Quoted 7 lines
Quoted 1 line

This could be the temporary solution.

As indicated - I don't think this is just a temporary solution. Beyond Xen, I simply don't see value in adding a linker flag (which then, sooner or later, llvm would also need to support just for Xen). The question rather is how to make the Xen side hack as little hacky as possible, without relying on the fragile behavior of objcopy.

Quoted 3 lines

Ok I didn't understand your previous answer, it's more clear now, thank you. Would you consider using a tool like this less fragile than objcopy:
https://github.com/fallen/keeprelocs ?

Well, something like that. Generalized enough to at least be halfway easy to later also use for further purposes, and if at all possible using the header we already have for PE (efi/pe.h).

Jan