diff mbox series

[v2,04/11] x86/mkreloc: print the linear address of relocations to read-only sections

Message ID 20250401130840.72119-5-roger.pau@citrix.com (mailing list archive)
State New
Headers show
Series x86/EFI: prevent write-execute sections | expand

Commit Message

Roger Pau Monne April 1, 2025, 1:08 p.m. UTC
Expand the warning message about relocations generated against read-only
sections, so it also contains the linear address of the offending
relocation, like:

Warning: relocation to r/o section .text:00000048 @ 0xffff82d040200048

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/efi/mkreloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Jan Beulich April 1, 2025, 3:55 p.m. UTC | #1
On 01.04.2025 15:08, Roger Pau Monne wrote:
> --- a/xen/arch/x86/efi/mkreloc.c
> +++ b/xen/arch/x86/efi/mkreloc.c
> @@ -270,8 +270,9 @@ static void diff_sections(const unsigned char *ptr1, const unsigned char *ptr2,
>  
>          if ( !(sec->flags & IMAGE_SCN_MEM_WRITE) )
>              fprintf(stderr,
> -                    "Warning: relocation to r/o section %s:%08" PRIxFAST32 "\n",
> -                    get_name(sec->name), i - disp);
> +                    "Warning: relocation to r/o section %s:%08" PRIxFAST32 " @ %p\n",
> +                    get_name(sec->name), i - disp,
> +                    (void *)(base + sec->rva + i - disp));

This being a build tool, it may be built/run as 32-bit code. I fear the
conversion to a pointer will not be liked by the compiler then, for (in
this case) really losing half of the bits.

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/efi/mkreloc.c b/xen/arch/x86/efi/mkreloc.c
index cc106bd875ba..fa50314ae945 100644
--- a/xen/arch/x86/efi/mkreloc.c
+++ b/xen/arch/x86/efi/mkreloc.c
@@ -270,8 +270,9 @@  static void diff_sections(const unsigned char *ptr1, const unsigned char *ptr2,
 
         if ( !(sec->flags & IMAGE_SCN_MEM_WRITE) )
             fprintf(stderr,
-                    "Warning: relocation to r/o section %s:%08" PRIxFAST32 "\n",
-                    get_name(sec->name), i - disp);
+                    "Warning: relocation to r/o section %s:%08" PRIxFAST32 " @ %p\n",
+                    get_name(sec->name), i - disp,
+                    (void *)(base + sec->rva + i - disp));
 
         printf("\t.word (%u << 12) | 0x%03" PRIxFAST32 "\n",
                reloc, sec->rva + i - disp - rva);