[commit: ghc] master: Abandon typedefing the {Section, ObjectCode}FormatInfo structs (81af480)

git at git.haskell.org git at git.haskell.org
Thu May 4 14:21:21 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/81af480a0fd3b37fff17245c1468638597261bcb/ghc

>---------------------------------------------------------------

commit 81af480a0fd3b37fff17245c1468638597261bcb
Author: Gabor Greif <ggreif at gmail.com>
Date:   Wed May 3 11:07:10 2017 +0200

    Abandon typedefing the {Section,ObjectCode}FormatInfo structs
    
    Summary:
    This is a follow-up to @angerman 's refactoring for ELF
    that happened with e5e8646d3c6af82549b55fbee6764b087144a7ec
    My previous commit a6675a93efe7cae2f206508047a39e73ce4e92a5
    corrected a typedef redefinition issue with GCC v4.4
    (which is pervasive with RHEL 6). Now the problem has resurfaced.
    
    Instead of dancing after the different compiler's pipe, I decided
    to eliminate the typedefs altogether and refer to the struct
    namespace explicitly.
    
    Added a note to describe why typedefs are not
    applied on customisable structs.
    
    Reviewers: austin, bgamari, erikd, simonmar
    
    Subscribers: rwbarton, thomie, angerman
    
    Differential Revision: https://phabricator.haskell.org/D3527


>---------------------------------------------------------------

81af480a0fd3b37fff17245c1468638597261bcb
 rts/Linker.c            |  2 +-
 rts/LinkerInternals.h   | 31 ++++++++++++++++++++++---------
 rts/linker/Elf.c        |  4 ++--
 rts/linker/ElfTypes.h   |  9 ++++-----
 rts/linker/MachOTypes.h |  8 ++++----
 5 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index f1ba84a..65caf89 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -1766,7 +1766,7 @@ addSection (Section *s, SectionKind kind, SectionAlloc alloc,
    s->mapped_start = mapped_start; /* start of mmap() block */
    s->mapped_size  = mapped_size;  /* size of mmap() block */
 
-   s->info = (SectionFormatInfo*)stgCallocBytes(1, sizeof(SectionFormatInfo),
+   s->info = (struct SectionFormatInfo*)stgCallocBytes(1, sizeof *s->info,
                                             "addSection(SectionFormatInfo)");
 
    IF_DEBUG(linker,
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
index 4574f39..a884561 100644
--- a/rts/LinkerInternals.h
+++ b/rts/LinkerInternals.h
@@ -20,9 +20,6 @@
 typedef void SymbolAddr;
 typedef char SymbolName;
 
-typedef struct _SectionFormatInfo SectionFormatInfo;
-typedef struct _ObjectCodeFormatInfo ObjectCodeFormatInfo;
-
 /* See Linker.c Note [runtime-linker-phases] */
 typedef enum {
     OBJECT_LOADED,
@@ -52,6 +49,18 @@ typedef
         }
    SectionAlloc;
 
+/*
+ * Note [No typedefs for customizable types]
+ * Some pointer-to-struct types are defined opaquely
+ * first, and customized later to architecture/ABI-specific
+ * instantiations. Having the usual
+ *   typedef struct _Foo {...} Foo;
+ * wrappers is hard to get right with older versions of GCC,
+ * so just have a
+ *   struct Foo {...};
+ * and always refer to it with the 'struct' qualifier.
+ */
+
 typedef
    struct _Section {
       void*    start;              /* actual start of section in memory */
@@ -66,8 +75,10 @@ typedef
       void* mapped_start;         /* start of mmap() block */
       StgWord mapped_size;        /* size of mmap() block */
 
-      /* A customizable type to augment the Section type. */
-       SectionFormatInfo* info;
+      /* A customizable type to augment the Section type.
+       * See Note [No typedefs for customizable types]
+       */
+      struct SectionFormatInfo* info;
    }
    Section;
 
@@ -142,8 +153,10 @@ typedef struct _ObjectCode {
     /* ptr to mem containing the object file image */
     char*      image;
 
-    /* A customizable type, that formats can use to augment ObjectCode */
-    ObjectCodeFormatInfo *info;
+    /* A customizable type, that formats can use to augment ObjectCode
+     * See Note [No typedefs for customizable types]
+     */
+    struct ObjectCodeFormatInfo* info;
 
     /* non-zero if the object file was mmap'd, otherwise malloc'd */
     int        imageMapped;
@@ -321,8 +334,8 @@ char *cstring_from_section_name(
 #  include "linker/ElfTypes.h"
 #elif defined (mingw32_HOST_OS)
 #  define OBJFORMAT_PEi386
-struct _SectionFormatInfo { void* placeholder; };
-struct _ObjectCodeFormatInfo { void* placeholder; };
+struct SectionFormatInfo { void* placeholder; };
+struct ObjectCodeFormatInfo { void* placeholder; };
 #elif defined(darwin_HOST_OS) || defined(ios_HOST_OS)
 #  define OBJFORMAT_MACHO
 #  include "linker/MachOTypes.h"
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index c1caf9a..da3e7c6 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -161,8 +161,8 @@ get_shndx_table(Elf_Ehdr* ehdr)
 void
 ocInit_ELF(ObjectCode * oc)
 {
-    oc->info = (ObjectCodeFormatInfo*)stgCallocBytes(
-            1, sizeof(ObjectCodeFormatInfo),
+    oc->info = (struct ObjectCodeFormatInfo*)stgCallocBytes(
+            1, sizeof *oc->info,
             "ocInit_Elf(ObjectCodeFormatInfo)");
     // TODO: fill info
     oc->info->elfHeader = (Elf_Ehdr *)oc->image;
diff --git a/rts/linker/ElfTypes.h b/rts/linker/ElfTypes.h
index a9f4a02..2f34d4a 100644
--- a/rts/linker/ElfTypes.h
+++ b/rts/linker/ElfTypes.h
@@ -130,7 +130,7 @@ typedef struct _ElfRelocationATable {
  * Header provides Information about the sections.
  *
  */
-typedef struct _ObjectCodeFormatInfo {
+struct ObjectCodeFormatInfo {
     Elf_Ehdr             *elfHeader;
     Elf_Phdr             *programHeader;
     Elf_Shdr             *sectionHeader;
@@ -144,8 +144,7 @@ typedef struct _ObjectCodeFormatInfo {
     /* pointer to the global offset table */
     void *                got_start;
     size_t                got_size;
-
-} ObjectCodeFormatInfo;
+};
 
 typedef
 struct _Stub {
@@ -154,7 +153,7 @@ struct _Stub {
     struct _Stub * next;
 } Stub;
 
-typedef struct _SectionFormatInfo {
+struct SectionFormatInfo {
     /*
      * The following fields are relevant for stubs next to sections only.
      */
@@ -166,6 +165,6 @@ typedef struct _SectionFormatInfo {
     char * name;
 
     Elf_Shdr *sectionHeader;
-} SectionFormatInfo;
+};
 #endif /* OBJECTFORMAT_ELF */
 #endif /* ElfTypes_h */
diff --git a/rts/linker/MachOTypes.h b/rts/linker/MachOTypes.h
index b7ee7e2..7d9d64c 100644
--- a/rts/linker/MachOTypes.h
+++ b/rts/linker/MachOTypes.h
@@ -38,7 +38,7 @@ typedef struct _MachOSymbol {
     MachONList * nlist; /* the nlist symbol entry */
 } MachOSymbol;
 
-typedef struct _ObjectCodeFormatInfo {
+struct ObjectCodeFormatInfo {
     // while we have the image
     // we can store some pointers
     // into it, so we don't have
@@ -63,7 +63,7 @@ typedef struct _ObjectCodeFormatInfo {
     /* pointer to the global offset table */
     void                 *got_start;
     size_t                got_size;
-} ObjectCodeFormatInfo;
+};
 
 /* When loading sections of the macho
  * into different pages, such that the
@@ -112,7 +112,7 @@ struct _Stub {
 }
 Stub;
 
-typedef struct _SectionFormatInfo {
+struct SectionFormatInfo {
     /*
      * The following fields are relevant for stubs next to sections only.
      */
@@ -126,6 +126,6 @@ typedef struct _SectionFormatInfo {
      */
     MachOSection * macho_section;
     MachORelocationInfo * relocation_info;
-} SectionFormatInfo;
+};
 
 #endif /* OBJECTFORMAT_MACHO */



More information about the ghc-commits mailing list