x86/EFI: warn about r/o sections requiring relocations
authorJan Beulich <jbeulich@suse.com>
Mon, 28 Aug 2017 08:50:29 +0000 (10:50 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 28 Aug 2017 08:50:29 +0000 (10:50 +0200)
EFI implementations may write-protect r/o sections, but we need to
apply relocations. Eliminate the one present case of a r/o section
with relocations (.init.text, which is now being combined with
.init.data into just .init).

Also correct a few other format strings (to account for the possibly
missing NUL in section names) in mkreloc.c.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/efi/mkreloc.c
xen/arch/x86/xen.lds.S

index bddcce07d30aac13ce46d17565263c67c5c13540..1aca79672a5501e5a59adeae36e8e59238b8f741 100644 (file)
@@ -66,8 +66,9 @@ struct coff_section {
     uint16_t relocation_count;
     uint16_t line_number_count;
     uint32_t flags;
-#define COFF_SECTION_BSS         0x00000080
-#define COFF_SECTION_DISCARDABLE 0x02000000
+#define COFF_SECTION_BSS         0x00000080U
+#define COFF_SECTION_DISCARDABLE 0x02000000U
+#define COFF_SECTION_WRITEABLE   0x80000000U
 };
 
 static void usage(const char *cmd, int rc)
@@ -224,7 +225,7 @@ static void diff_sections(const unsigned char *ptr1, const unsigned char *ptr2,
         if ( i < disp || i + width - disp > sec->file_size )
         {
             fprintf(stderr,
-                    "Bogus difference at %s:%08" PRIxFAST32 "\n",
+                    "Bogus difference at %.8s:%08" PRIxFAST32 "\n",
                     sec->name, i);
             exit(3);
         }
@@ -235,7 +236,7 @@ static void diff_sections(const unsigned char *ptr1, const unsigned char *ptr2,
         if ( delta != diff )
         {
             fprintf(stderr,
-                    "Difference at %s:%08" PRIxFAST32 " is %#" PRIxFAST64
+                    "Difference at %.8s:%08" PRIxFAST32 " is %#" PRIxFAST64
                     " (expected %#" PRIxFAST64 ")\n",
                     sec->name, i, delta, diff);
             continue;
@@ -261,11 +262,16 @@ static void diff_sections(const unsigned char *ptr1, const unsigned char *ptr2,
         else if ( rva != cur_rva )
         {
             fprintf(stderr,
-                    "Cannot handle decreasing RVA (at %s:%08" PRIxFAST32 ")\n",
+                    "Cannot handle decreasing RVA (at %.8s:%08" PRIxFAST32 ")\n",
                     sec->name, i);
             exit(3);
         }
 
+        if ( !(sec->flags & COFF_SECTION_WRITEABLE) )
+            fprintf(stderr,
+                    "Warning: relocation to r/o section %.8s:%08" PRIxFAST32 "\n",
+                    sec->name, i);
+
         printf("\t.word (%u << 12) | 0x%03" PRIxFAST32 "\n",
                reloc, sec->rva + i - disp - rva);
         reloc_size += 2;
index ff08bbe42acd488fe72b6abf7b78b733bae83ee3..e48ab6a1ad17f034fbab66e6d8d5b02059a6dea0 100644 (file)
@@ -155,7 +155,7 @@ SECTIONS
   __2M_init_start = .;         /* Start of 2M superpages, mapped RWX (boot only). */
   . = ALIGN(PAGE_SIZE);             /* Init code and data */
   __init_begin = .;
-  .init.text : {
+  .init : {
        _sinittext = .;
        *(.init.text)
        /*
@@ -165,8 +165,9 @@ SECTIONS
         */
        *(.altinstr_replacement)
        _einittext = .;
-  } :text
-  .init.data : {
+
+       . = ALIGN(SMP_CACHE_BYTES);
+
        *(.init.rodata)
        *(.init.rodata.rel)
        *(.init.rodata.str*)