tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Section, ints and Elf32_Words


From: Peter \"Firefly\" Lund
Subject: [Tinycc-devel] Section, ints and Elf32_Words
Date: Fri, 2 May 2003 20:44:48 +0200 (MEST)

TinyCC defines a section structure in tcc.c like this:

typedef struct Section {
    unsigned long data_offset; /* current data offset */
    unsigned char *data;       /* section data */
    unsigned long data_allocated; /* used for realloc() handling */
    int sh_name;             /* elf section name (only used during output) */
    int sh_num;              /* elf section number */
    int sh_type;             /* elf section type */
    int sh_flags;            /* elf section flags */
    int sh_info;             /* elf section info */
    int sh_addralign;        /* elf section alignment */
    int sh_entsize;          /* elf entry size */
    unsigned long sh_size;   /* section size (only used during output) */
    unsigned long sh_addr;      /* address at which the section is relocated */
    unsigned long sh_offset;      /* address at which the section is relocated 
*/
    int nb_hashed_syms;      /* used to resize the hash table */
    struct Section *link;    /* link to another section */
    struct Section *reloc;   /* corresponding section for relocation, if any */
    struct Section *hash;     /* hash table for symbols */
    struct Section *next;
    char name[64];           /* section name */
} Section;


Many of the fields are carried straight over to a structure in elf.h like
this:

typedef struct
{
  Elf32_Word    sh_name;                /* Section name (string tbl index) */
  Elf32_Word    sh_type;                /* Section type */
  Elf32_Word    sh_flags;               /* Section flags */
  Elf32_Addr    sh_addr;                /* Section virtual addr at execution */
  Elf32_Off     sh_offset;              /* Section file offset */
  Elf32_Word    sh_size;                /* Section size in bytes */
  Elf32_Word    sh_link;                /* Link to another section */
  Elf32_Word    sh_info;                /* Additional section information */
  Elf32_Word    sh_addralign;           /* Section alignment */
  Elf32_Word    sh_entsize;             /* Entry size if section holds table */
} Elf32_Shdr;


(There is a similar structure with Elf64_Words for 64-bit targets)

Elf32_Word is unsigned and the fields in Section use a normal int.  I
think we at least want to change those into unsigned and possibly just
into Elf32_Word... Or maybe we'd like to use Elf32_Shdr directly inside
Section:

typedef struct Section {
    unsigned long data_offset; /* current data offset */
    unsigned char *data;       /* section data */
    unsigned long data_allocated; /* used for realloc() handling */
    Elf32_Shdr sec_head;     /* ELF section header - not all fields are
                              * used during compilation
                              */
    int nb_hashed_syms;      /* used to resize the hash table */
    struct Section *link;    /* link to another section */
    struct Section *reloc;   /* corresponding section for relocation, if any */
    struct Section *hash;     /* hash table for symbols */
    struct Section *next;
    char name[64];           /* section name */
} Section;

Of course this would change to Elf64_Shdr for 64-bit targets.

Comments?

-Peter

"Of course, I'm not unbiased, but in my humble opinion, I've
 gotten close to something that I can be really proud of."
 -- Knuth on The Art of Computer Programming.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]