Browse Source

Merge pull request #96 from lzha101/master

Fix alignment issue for metadata section

Signed-off-by: Zhang Lili  <lili.z.zhang@intel.com>
lzha101 7 years ago
parent
commit
fd91609f54
2 changed files with 3 additions and 11 deletions
  1. 1 9
      psw/urts/parser/elfparser.cpp
  2. 2 2
      sdk/trts/linux/metadata_sec.S

+ 1 - 9
psw/urts/parser/elfparser.cpp

@@ -34,8 +34,6 @@
 #include "se_memcpy.h"
 #include "global_data.h"
 
-#define META_SECTION_ALIGNMENT    1  /*metadata section no alignment*/
-
 namespace {
 /** the callback function to filter a section.
  *
@@ -388,16 +386,10 @@ bool get_meta_property(const uint8_t *start_addr, const ElfW(Ehdr) *elf_hdr, uin
      * |  metadata       |
      */
 
-    if (shdr->sh_addralign != META_SECTION_ALIGNMENT)
-    {
-        se_trace(SE_TRACE_ERROR, "ERROR: The '.note.sgxmeta' section must be 4byte aligned\n");
-        return false;
-    }
-
     const ElfW(Note) *note = GET_PTR(ElfW(Note), start_addr, shdr->sh_offset);
     assert(note != NULL);
 
-    if (shdr->sh_size != ROUND_TO(sizeof(ElfW(Note)) + note->namesz + note->descsz, META_SECTION_ALIGNMENT))
+    if (shdr->sh_size != ROUND_TO(sizeof(ElfW(Note)) + note->namesz + note->descsz, shdr->sh_addralign))
     {
         se_trace(SE_TRACE_ERROR, "ERROR: The '.note.sgxmeta' section size is not correct.\n");
         return false;

+ 2 - 2
sdk/trts/linux/metadata_sec.S

@@ -33,10 +33,10 @@
 
 #define METADATA_SIZE 4096
 .section ".note.sgxmeta", "", @note
-    .p2align 0              /* section no alignment */
+    .p2align 2              /* section alignment */
     .long 1f - 0f           /* name size (not including padding) */
     .long 2f - 1f           /* desc size (not including padding) */
     .long 0x01              /* type */
 0:  .asciz "sgx_metadata"   /* name */
 1:  .fill METADATA_SIZE, 1, 0      /* desc - stand for metadata which is initialized with 0 */
-2:  .p2align 0
+2:  .p2align 2