Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
em_elf.cxx File Reference
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <bstring.h>
#include <elf.h>
#include <elfaccess.h>
#include <libelf.h>
#include <stamp.h>
#include <alloca.h>
#include <assert.h>
#include <cmplrs/leb128.h>
#include <cmplrs/elf_interfaces.h>
#include "defs.h"
#include "erlib.h"
#include "erglob.h"
#include "config.h"
#include "targ_const.h"
#include "glob.h"
#include "config_elf_targ.h"
#include "em_elf.h"
#include "targ_em_elf.h"
Include dependency graph for em_elf.cxx:

Go to the source code of this file.

Defines

#define USE_STANDARD_TYPES   1
#define MAX_EV_SIZE   64000

Functions

static void Increase_Data_Buffer_Size (pSCNINFO scninfo, Elf64_Xword newsize)
void Em_Change_Section_Origin (pSCNINFO scn, Elf64_Xword scn_ofst)
void Em_Change_Section_Alignment (pSCNINFO scn, Elf64_Word scn_align)
Elf64_Xword Em_Add_Bytes_To_Scn (pSCNINFO scninfo, void *input_buf, Elf64_Xword length, Elf64_Word align)
Elf64_Xword Em_Add_Zeros_To_Scn (pSCNINFO scninfo, Elf64_Word length, Elf64_Word align)
Elf64_Xword Em_Add_Address_To_Scn (pSCNINFO scninfo, Elf64_Word symindex, Elf64_Sxword addend, Elf64_Word align)
Elf64_Xword Em_Add_Displacement_To_Scn (pSCNINFO scninfo, Elf64_Word symindex, Elf64_Sxword addend, Elf64_Word align)
static Elf64_Word String_To_Index (pSCNINFO strinfo, char *scn_name)
static char * Index_To_String (pSCNINFO strinfo, Elf64_Word index)
static void print_elf_error (void)
static Elf_Scn * Create_New_Section (char *scn_name, Elf64_Word scn_type, Elf64_Xword scn_flags, Elf64_Xword scn_entsize)
void Em_Set_sh_link (pSCNINFO scn, Elf64_Word link)
void Em_Set_sh_info (pSCNINFO scn, Elf64_Word info)
static void Update_Data (pSCNINFO scninfo, Elf_Type type)
size_t Em_Get_Section_Index (pSCNINFO scn)
Elf64_Xword Em_Get_Section_Offset (pSCNINFO scn)
char * Em_Get_Section_Name (pSCNINFO scninfo)
Elf64_Word Em_Get_Section_Type (pSCNINFO scninfo)
Elf64_Word Em_Get_Section_Flags (pSCNINFO scninfo)
Elf64_Word Em_Get_Section_Entsize (pSCNINFO scninfo)
Elf64_Word Em_Get_Section_Align (pSCNINFO scninfo)
Elf64_Word Em_Get_Section_Info (pSCNINFO scninfo)
static void Create_New_Relocation_Section (BOOL is_rela, pSCNINFO scninfo)
void Em_Add_New_Rel (Elf64_Word symindex, unsigned char reltype, Elf64_Addr reloffset, pSCNINFO scninfo)
void Em_Add_New_Rela (Elf64_Word symindex, unsigned char reltype, Elf64_Addr reloffset, Elf64_Sxword addend, pSCNINFO scninfo)
void Em_Add_New_Composite_Rela (Elf64_Rela *preloc, pSCNINFO scninfo)
void Em_Define_Symbol (Elf64_Word symindex, Elf64_Addr symvalue, Elf64_Xword symsize, pSCNINFO scninfo)
void Em_Undefine_Symbol (Elf64_Word symindex)
void Em_Set_Symbol_Binding (Elf64_Word symindex, unsigned char symbind)
char * Em_Get_Symbol_Name (Elf64_Word symindex)
Elf64_Word Em_Add_New_Symbol (char *symname, Elf64_Addr symvalue, Elf64_Xword symsize, unsigned char symbind, unsigned char symtype, unsigned char symother, Elf64_Half symshndx)
Elf64_Word Em_Add_New_Undef_Symbol (char *symname, unsigned char symbind, unsigned char symtype, unsigned char symother)
Elf64_Word Em_Add_New_Weak_Symbol (char *weakname, unsigned char symtype, unsigned char symother, Elf64_Word symindex)
static void Update_Addr_Reset_Size (pSCNINFO ev_scn)
void Generate_Addr_Reset (pSCNINFO scn, BOOL is_events, Elf64_Xword ev_ofst)
void Set_Current_Location (pSCNINFO scn, BOOL is_events, Elf64_Word ev_ofst)
void Em_Add_New_Interface (Elf64_Word length, Elf64_Byte *data)
void Em_Add_Comment (char *s)
static void Create_Elf_Header (INT isa, BOOL old_abi, BOOL big_endian, BOOL pic, BOOL cpic, BOOL xgot, BOOL gp_groups)
static void Read_Section (pSCNINFO scninfo, Elf64_Word scndx)
static void Read_Elf_File (void)
int Em_Begin_File (char *ofilename, BOOL update, BOOL elf64, BOOL old_abi, INT isa, BOOL big_endian, BOOL pic, BOOL cpic, BOOL xgot, BOOL gp_groups, BOOL elf_trace)
void Em_End_File (void)
pSCNINFO Em_New_Section (char *scnname, Elf64_Word scntype, Elf64_Xword scnflags, Elf64_Xword scnentsize, Elf64_Xword scnalign)
void Em_End_Section (pSCNINFO scninfo)
void Em_New_Data_Buffer (pSCNINFO scninfo, Elf64_Xword size, int alignment)
Elf64_Word Em_Create_Section_Symbol (pSCNINFO scninfo)

Variables

static SCNINFO Shstrtab_Info
static SCNINFO Strtab_Info
static SCNINFO Symtab_Info_struct
pSCNINFO Symtab_Info = &Symtab_Info_struct
static pSCNINFO Comment_Scn
static char * object_file_name
static Elf * Elf_Ptr
pSCNINFO Options_Scn
BOOL Sixtyfour_Bit
static BOOL Big_Endian

Define Documentation

#define MAX_EV_SIZE   64000

Definition at line 1001 of file em_elf.cxx.

Referenced by Set_Current_Location().

#define USE_STANDARD_TYPES   1

Definition at line 64 of file em_elf.cxx.


Function Documentation

void Em_Add_Comment ( char *  s)

Definition at line 1077 of file em_elf.cxx.

References ELF_COMMENT, Em_Add_Bytes_To_Scn(), Em_New_Section(), INCLUDE_STAMP, NULL, object_file_name, s, and SHT_PROGBITS.

Here is the call graph for this function:

Elf64_Xword Em_Add_Displacement_To_Scn ( pSCNINFO  scninfo,
Elf64_Word  symindex,
Elf64_Sxword  addend,
Elf64_Word  align 
)

Definition at line 279 of file em_elf.cxx.

References Em_Add_Bytes_To_Scn(), Em_Add_New_Rel(), and R_SCN_DISP.

Here is the call graph for this function:

void Em_Add_New_Interface ( Elf64_Word  length,
Elf64_Byte data 
)

Definition at line 1058 of file em_elf.cxx.

References ELF32_FSZ_WORD, Em_Add_Bytes_To_Scn(), Em_New_Section(), Em_Set_sh_link(), Interface_Scn, NULL, SCNINFO_index, SECT_IFACE_NAME, SHF_NOSTRIP, and SHT_IRIX_IFACE.

Here is the call graph for this function:

void Em_Add_New_Rela ( Elf64_Word  symindex,
unsigned char  reltype,
Elf64_Addr  reloffset,
Elf64_Sxword  addend,
pSCNINFO  scninfo 
)
Elf64_Word Em_Add_New_Undef_Symbol ( char *  symname,
unsigned char  symbind,
unsigned char  symtype,
unsigned char  symother 
)

Definition at line 902 of file em_elf.cxx.

References Em_Add_New_Symbol(), and SHN_UNDEF.

Here is the call graph for this function:

Elf64_Word Em_Add_New_Weak_Symbol ( char *  weakname,
unsigned char  symtype,
unsigned char  symother,
Elf64_Word  symindex 
)

Definition at line 917 of file em_elf.cxx.

References EC_Elf_Idx, Em_Add_New_Symbol(), ErrMsg(), SCNINFO_buffer, SCNINFO_size, Sixtyfour_Bit, and STB_WEAK.

Here is the call graph for this function:

Elf64_Xword Em_Add_Zeros_To_Scn ( pSCNINFO  scninfo,
Elf64_Word  length,
Elf64_Word  align 
)

Definition at line 208 of file em_elf.cxx.

References buf, EC_No_Mem, Em_Add_Bytes_To_Scn(), ErrMsg(), free(), and NULL.

Referenced by Em_Add_Address_To_Scn().

Here is the call graph for this function:

int Em_Begin_File ( char *  ofilename,
BOOL  update,
BOOL  elf64,
BOOL  old_abi,
INT  isa,
BOOL  big_endian,
BOOL  pic,
BOOL  cpic,
BOOL  xgot,
BOOL  gp_groups,
BOOL  elf_trace 
)
void Em_Change_Section_Alignment ( pSCNINFO  scn,
Elf64_Word  scn_align 
)

Definition at line 152 of file em_elf.cxx.

References SCNINFO_align.

void Em_Change_Section_Origin ( pSCNINFO  scn,
Elf64_Xword  scn_ofst 
)

Definition at line 145 of file em_elf.cxx.

References SCNINFO_offset.

void Em_Define_Symbol ( Elf64_Word  symindex,
Elf64_Addr  symvalue,
Elf64_Xword  symsize,
pSCNINFO  scninfo 
)
void Em_End_File ( void  )

Definition at line 1295 of file em_elf.cxx.

References Elf_Ptr, Em_End_Section(), Interface_Scn, NULL, print_elf_error(), and Update_Data().

Here is the call graph for this function:

void Em_End_Section ( pSCNINFO  scninfo)

Definition at line 1341 of file em_elf.cxx.

References Em_End_Section(), free(), NULL, SCNINFO_contents, SCNINFO_events, SCNINFO_relainfo, SCNINFO_relinfo, Update_Addr_Reset_Size(), and Update_Data().

Referenced by Em_Dwarf_Write_Scns(), Em_End_File(), and Em_End_Section().

Here is the call graph for this function:

Definition at line 507 of file em_elf.cxx.

References SCNINFO_scnptr, and Sixtyfour_Bit.

Definition at line 496 of file em_elf.cxx.

References SCNINFO_scnptr, and Sixtyfour_Bit.

Definition at line 485 of file em_elf.cxx.

References SCNINFO_scnptr, and Sixtyfour_Bit.

Definition at line 442 of file em_elf.cxx.

References SCNINFO_index.

Referenced by Em_Dwarf_Find_Dwarf_Scn(), and setup_new_section_for_dwarf().

Definition at line 518 of file em_elf.cxx.

References SCNINFO_scnptr, and Sixtyfour_Bit.

Definition at line 449 of file em_elf.cxx.

References SCNINFO_offset.

Definition at line 474 of file em_elf.cxx.

References SCNINFO_scnptr, and Sixtyfour_Bit.

char* Em_Get_Symbol_Name ( Elf64_Word  symindex)

Definition at line 815 of file em_elf.cxx.

References EC_Elf_Idx, ErrMsg(), Index_To_String(), SCNINFO_buffer, SCNINFO_size, and Sixtyfour_Bit.

Here is the call graph for this function:

void Em_New_Data_Buffer ( pSCNINFO  scninfo,
Elf64_Xword  size,
int  alignment 
)

Definition at line 1364 of file em_elf.cxx.

References Increase_Data_Buffer_Size(), Roundup, SCNINFO_align, and SCNINFO_size.

Here is the call graph for this function:

pSCNINFO Em_New_Section ( char *  scnname,
Elf64_Word  scntype,
Elf64_Xword  scnflags,
Elf64_Xword  scnentsize,
Elf64_Xword  scnalign 
)
void Em_Set_Symbol_Binding ( Elf64_Word  symindex,
unsigned char  symbind 
)

Definition at line 762 of file em_elf.cxx.

References EC_Elf_Idx, ELF32_ST_INFO, ELF32_ST_TYPE, ELF64_ST_INFO, ELF64_ST_TYPE, ErrMsg(), SCNINFO_buffer, SCNINFO_size, Sixtyfour_Bit, Elf32_Sym::st_info, and Elf64_Sym::st_info.

Here is the call graph for this function:

void Em_Undefine_Symbol ( Elf64_Word  symindex)

Definition at line 737 of file em_elf.cxx.

References EC_Elf_Idx, ErrMsg(), SCNINFO_buffer, SCNINFO_size, SHN_UNDEF, Sixtyfour_Bit, Elf32_Sym::st_shndx, and Elf64_Sym::st_shndx.

Here is the call graph for this function:

void Generate_Addr_Reset ( pSCNINFO  scn,
BOOL  is_events,
Elf64_Xword  ev_ofst 
)
static void Increase_Data_Buffer_Size ( pSCNINFO  scninfo,
Elf64_Xword  newsize 
) [static]

Definition at line 115 of file em_elf.cxx.

References bzero(), EC_Elf_Size64, EC_No_Mem, ErrMsg(), NULL, SCNINFO_buffer, and SCNINFO_limit.

Referenced by Em_Add_Bytes_To_Scn(), and Em_New_Data_Buffer().

Here is the call graph for this function:

static char* Index_To_String ( pSCNINFO  strinfo,
Elf64_Word  index 
) [static]

Definition at line 315 of file em_elf.cxx.

References SCNINFO_buffer.

Referenced by Em_Get_Symbol_Name().

static void print_elf_error ( void  ) [static]

Definition at line 323 of file em_elf.cxx.

References EC_Elf_Error, and ErrMsg().

Referenced by Create_New_Section(), Em_Begin_File(), Em_End_File(), and Update_Data().

Here is the call graph for this function:

static void Read_Elf_File ( void  ) [static]

Definition at line 1197 of file em_elf.cxx.

References Elf_Ptr, NULL, Read_Section(), SHT_SYMTAB, and Sixtyfour_Bit.

Referenced by Em_Begin_File().

Here is the call graph for this function:

static void Read_Section ( pSCNINFO  scninfo,
Elf64_Word  scndx 
) [static]

Definition at line 1177 of file em_elf.cxx.

References bzero(), Elf_Ptr, Em_Add_Bytes_To_Scn(), NULL, and SCNINFO_scnptr.

Referenced by Read_Elf_File().

Here is the call graph for this function:

static Elf64_Word String_To_Index ( pSCNINFO  strinfo,
char *  scn_name 
) [static]

Definition at line 299 of file em_elf.cxx.

References buf, Em_Add_Bytes_To_Scn(), NULL, SCNINFO_buffer, and SCNINFO_size.

Referenced by Create_New_Section().

Here is the call graph for this function:

static void Update_Addr_Reset_Size ( pSCNINFO  ev_scn) [static]

Definition at line 954 of file em_elf.cxx.

References SCNINFO_buffer, SCNINFO_ev_offset, SCNINFO_offset, and size.

Referenced by Em_End_Section(), and Set_Current_Location().

static void Update_Data ( pSCNINFO  scninfo,
Elf_Type  type 
) [static]

Definition at line 418 of file em_elf.cxx.

References NULL, print_elf_error(), SCNINFO_align, SCNINFO_buffer, SCNINFO_limit, SCNINFO_scnptr, and SCNINFO_size.

Referenced by Em_End_File(), and Em_End_Section().

Here is the call graph for this function:


Variable Documentation

BOOL Big_Endian [static]

Definition at line 97 of file em_elf.cxx.

Referenced by Em_Begin_File().

Definition at line 84 of file em_elf.cxx.

char* object_file_name [static]

Definition at line 85 of file em_elf.cxx.

Referenced by Em_Add_Comment(), and Em_Begin_File().

Definition at line 92 of file em_elf.cxx.

Referenced by Em_Add_New_Option().

Definition at line 78 of file em_elf.cxx.

SCNINFO Strtab_Info [static]

Definition at line 79 of file em_elf.cxx.

Definition at line 82 of file em_elf.cxx.

Referenced by setup_new_section_for_dwarf().

Definition at line 80 of file em_elf.cxx.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines