Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
#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"
Go to the source code of this file.
#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.
static void Create_Elf_Header | ( | INT | isa, |
BOOL | old_abi, | ||
BOOL | big_endian, | ||
BOOL | pic, | ||
BOOL | cpic, | ||
BOOL | xgot, | ||
BOOL | gp_groups | ||
) | [static] |
Definition at line 1098 of file em_elf.cxx.
References Config_ELF_From_Target(), Create_New_Section(), Elf32_Ehdr::e_flags, Elf64_Ehdr::e_flags, Elf32_Ehdr::e_ident, Elf64_Ehdr::e_ident, Elf32_Ehdr::e_machine, Elf64_Ehdr::e_machine, Elf32_Ehdr::e_shstrndx, Elf64_Ehdr::e_shstrndx, Elf32_Ehdr::e_type, Elf64_Ehdr::e_type, EF_MIPS_CPIC, EF_MIPS_OPTIONS_FIRST, EF_MIPS_PIC, EF_MIPS_XGOT, EI_DATA, Elf_Ptr, ELF_SHSTRTAB, ELF_STRTAB, ELF_SYMTAB, ELFDATA2LSB, ELFDATA2MSB, Em_Add_Bytes_To_Scn(), Em_Add_New_Symbol(), Em_Set_sh_link(), ET_REL, Get_Elf_Target_Machine(), NULL, SCNINFO_index, SCNINFO_scnptr, section_info::scnptr, Set_Elf_Version(), SHF_ALLOC, SHN_UNDEF, SHT_STRTAB, SHT_SYMTAB, Sixtyfour_Bit, STB_LOCAL, and STT_NOTYPE.
Referenced by Em_Begin_File().
static void Create_New_Relocation_Section | ( | BOOL | is_rela, |
pSCNINFO | scninfo | ||
) | [static] |
Definition at line 532 of file em_elf.cxx.
References ELF32_FSZ_WORD, ELF64_FSZ_XWORD, Em_Get_Section_Name(), Em_New_Section(), Em_Set_sh_info(), Em_Set_sh_link(), SCNINFO_index, SCNINFO_relainfo, SCNINFO_relinfo, SHT_REL, SHT_RELA, Sixtyfour_Bit, and strcpy.
Referenced by Em_Add_New_Composite_Rela(), Em_Add_New_Rel(), and Em_Add_New_Rela().
static Elf_Scn* Create_New_Section | ( | char * | scn_name, |
Elf64_Word | scn_type, | ||
Elf64_Xword | scn_flags, | ||
Elf64_Xword | scn_entsize | ||
) | [static] |
Definition at line 336 of file em_elf.cxx.
References Elf_Ptr, FALSE, print_elf_error(), Elf32_Shdr::sh_addr, Elf64_Shdr::sh_addr, Elf32_Shdr::sh_entsize, Elf64_Shdr::sh_entsize, Elf32_Shdr::sh_flags, Elf64_Shdr::sh_flags, Elf32_Shdr::sh_name, Elf64_Shdr::sh_name, Elf32_Shdr::sh_type, Elf64_Shdr::sh_type, Sixtyfour_Bit, and String_To_Index().
Referenced by Create_Elf_Header(), and Em_New_Section().
Elf64_Xword Em_Add_Address_To_Scn | ( | pSCNINFO | scninfo, |
Elf64_Word | symindex, | ||
Elf64_Sxword | addend, | ||
Elf64_Word | align | ||
) |
Definition at line 236 of file em_elf.cxx.
References Em_Add_Bytes_To_Scn(), Em_Add_New_Rel(), Em_Add_New_Rela(), Em_Add_Zeros_To_Scn(), R_WORD32, R_WORD64, SCNINFO_scnptr, Elf32_Shdr::sh_flags, Elf64_Shdr::sh_flags, SHF_MERGE, and Sixtyfour_Bit.
Elf64_Xword Em_Add_Bytes_To_Scn | ( | pSCNINFO | scninfo, |
void * | input_buf, | ||
Elf64_Xword | length, | ||
Elf64_Word | align | ||
) |
Definition at line 161 of file em_elf.cxx.
References EC_Elf_Size64, ErrMsg(), Increase_Data_Buffer_Size(), NULL, Roundup, SCNINFO_align, SCNINFO_buffer, SCNINFO_limit, SCNINFO_offset, and SCNINFO_size.
Referenced by Create_Elf_Header(), Em_Add_Address_To_Scn(), Em_Add_Comment(), Em_Add_Displacement_To_Scn(), Em_Add_New_Composite_Rela(), Em_Add_New_Interface(), Em_Add_New_Option(), Em_Add_New_Rel(), Em_Add_New_Rela(), Em_Add_New_Symbol(), Em_Add_Zeros_To_Scn(), Em_Dwarf_Write_Scns(), Em_Targ_Emit_Const(), Generate_Addr_Reset(), Read_Section(), Set_Current_Location(), and String_To_Index().
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.
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.
void Em_Add_New_Composite_Rela | ( | Elf64_Rela * | preloc, |
pSCNINFO | scninfo | ||
) |
Definition at line 659 of file em_elf.cxx.
References Create_New_Relocation_Section(), ELF32_FSZ_WORD, ELF64_FSZ_XWORD, Em_Add_Bytes_To_Scn(), NULL, R_NONE, REL64_sym, REL64_type, REL64_type2, REL64_type3, REL_addend, REL_offset, SCNINFO_relainfo, Set_REL32_info, Sixtyfour_Bit, and TRUE.
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.
void Em_Add_New_Rel | ( | Elf64_Word | symindex, |
unsigned char | reltype, | ||
Elf64_Addr | reloffset, | ||
pSCNINFO | scninfo | ||
) |
Definition at line 570 of file em_elf.cxx.
References Create_New_Relocation_Section(), EC_Elf_Idx, ELF32_FSZ_WORD, ELF64_FSZ_XWORD, Em_Add_Bytes_To_Scn(), ErrMsg(), FALSE, NULL, REL64_ssym, REL64_type2, REL64_type3, REL_offset, SCNINFO_relinfo, Set_REL32_info, Set_REL64_info, and Sixtyfour_Bit.
Referenced by Em_Add_Address_To_Scn(), Em_Add_Displacement_To_Scn(), and Generate_Addr_Reset().
void Em_Add_New_Rela | ( | Elf64_Word | symindex, |
unsigned char | reltype, | ||
Elf64_Addr | reloffset, | ||
Elf64_Sxword | addend, | ||
pSCNINFO | scninfo | ||
) |
Definition at line 621 of file em_elf.cxx.
References Create_New_Relocation_Section(), ELF32_FSZ_WORD, ELF64_FSZ_XWORD, Em_Add_Bytes_To_Scn(), NULL, REL64_ssym, REL64_type2, REL64_type3, REL_addend, REL_offset, SCNINFO_relainfo, Set_REL32_info, Set_REL64_info, Sixtyfour_Bit, and TRUE.
Referenced by Em_Add_Address_To_Scn().
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 | ||
) |
Definition at line 837 of file em_elf.cxx.
References ELF32_FSZ_WORD, ELF32_ST_INFO, ELF64_FSZ_XWORD, ELF64_ST_INFO, Em_Add_Bytes_To_Scn(), NULL, Sixtyfour_Bit, Elf32_Sym::st_info, Elf64_Sym::st_info, Elf32_Sym::st_name, Elf64_Sym::st_name, Elf32_Sym::st_other, Elf64_Sym::st_other, Elf32_Sym::st_shndx, Elf64_Sym::st_shndx, Elf32_Sym::st_size, Elf64_Sym::st_size, Elf32_Sym::st_value, and Elf64_Sym::st_value.
Referenced by Create_Elf_Header(), Em_Add_New_Undef_Symbol(), Em_Add_New_Weak_Symbol(), and Em_Create_Section_Symbol().
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.
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.
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().
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 | ||
) |
Definition at line 1223 of file em_elf.cxx.
References Big_Endian, cmd, Create_Elf_Header(), EC_Obj_Create, EC_Obj_Delete, Elf_Ptr, ErrMsg(), errno, EV_CURRENT, EV_NONE, Interface_Scn, NULL, object_file_name, open, print_elf_error(), Read_Elf_File(), result, Sixtyfour_Bit, stat, and unlink.
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.
Elf64_Word Em_Create_Section_Symbol | ( | pSCNINFO | scninfo | ) |
Definition at line 1376 of file em_elf.cxx.
References Em_Add_New_Symbol(), Em_Get_Section_Name(), SCNINFO_index, SCNINFO_scnidx, STB_LOCAL, and STT_SECTION.
Referenced by Em_Dwarf_End_Text_Arange(), Em_Dwarf_Start_Text_Lines(), Generate_Addr_Reset(), and setup_new_section_for_dwarf().
void Em_Define_Symbol | ( | Elf64_Word | symindex, |
Elf64_Addr | symvalue, | ||
Elf64_Xword | symsize, | ||
pSCNINFO | scninfo | ||
) |
Definition at line 700 of file em_elf.cxx.
References EC_Elf_Idx, ErrMsg(), SCNINFO_buffer, SCNINFO_index, SCNINFO_size, Sixtyfour_Bit, Elf32_Sym::st_shndx, Elf64_Sym::st_shndx, Elf32_Sym::st_size, Elf64_Sym::st_size, Elf32_Sym::st_value, and Elf64_Sym::st_value.
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().
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().
Elf64_Word Em_Get_Section_Align | ( | pSCNINFO | scninfo | ) |
Definition at line 507 of file em_elf.cxx.
References SCNINFO_scnptr, and Sixtyfour_Bit.
Elf64_Word Em_Get_Section_Entsize | ( | pSCNINFO | scninfo | ) |
Definition at line 496 of file em_elf.cxx.
References SCNINFO_scnptr, and Sixtyfour_Bit.
Elf64_Word Em_Get_Section_Flags | ( | pSCNINFO | scninfo | ) |
Definition at line 485 of file em_elf.cxx.
References SCNINFO_scnptr, and Sixtyfour_Bit.
size_t Em_Get_Section_Index | ( | pSCNINFO | scn | ) |
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().
Elf64_Word Em_Get_Section_Info | ( | pSCNINFO | scninfo | ) |
Definition at line 518 of file em_elf.cxx.
References SCNINFO_scnptr, and Sixtyfour_Bit.
char* Em_Get_Section_Name | ( | pSCNINFO | scninfo | ) |
Definition at line 456 of file em_elf.cxx.
References section_info::buffer, SCNINFO_scnptr, Elf32_Shdr::sh_name, Elf64_Shdr::sh_name, and Sixtyfour_Bit.
Referenced by Create_New_Relocation_Section(), Em_Create_Section_Symbol(), Em_Dwarf_Find_Dwarf_Scn_By_Name(), and Em_Dwarf_Write_Scns().
Definition at line 449 of file em_elf.cxx.
References SCNINFO_offset.
Elf64_Word Em_Get_Section_Type | ( | pSCNINFO | scninfo | ) |
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.
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.
pSCNINFO Em_New_Section | ( | char * | scnname, |
Elf64_Word | scntype, | ||
Elf64_Xword | scnflags, | ||
Elf64_Xword | scnentsize, | ||
Elf64_Xword | scnalign | ||
) |
Definition at line 1319 of file em_elf.cxx.
References bzero(), Create_New_Section(), EC_No_Mem, ErrMsg(), NULL, SCNINFO_align, and SCNINFO_scnptr.
Referenced by Create_New_Relocation_Section(), Em_Add_Comment(), Em_Add_New_Interface(), Em_Add_New_Option(), and setup_new_section_for_dwarf().
void Em_Set_sh_info | ( | pSCNINFO | scn, |
Elf64_Word | info | ||
) |
Definition at line 399 of file em_elf.cxx.
References SCNINFO_scnptr, Elf32_Shdr::sh_info, Elf64_Shdr::sh_info, and Sixtyfour_Bit.
Referenced by Create_New_Relocation_Section(), and setup_new_section_for_dwarf().
void Em_Set_sh_link | ( | pSCNINFO | scn, |
Elf64_Word | link | ||
) |
Definition at line 383 of file em_elf.cxx.
References SCNINFO_scnptr, Elf32_Shdr::sh_link, Elf64_Shdr::sh_link, and Sixtyfour_Bit.
Referenced by Create_Elf_Header(), Create_New_Relocation_Section(), Em_Add_New_Interface(), and setup_new_section_for_dwarf().
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.
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.
void Generate_Addr_Reset | ( | pSCNINFO | scn, |
BOOL | is_events, | ||
Elf64_Xword | ev_ofst | ||
) |
Definition at line 969 of file em_elf.cxx.
References dummy, EC_Elf_Ofst64, EK_ADDR_RESET, Em_Add_Bytes_To_Scn(), Em_Add_New_Rel(), Em_Create_Section_Symbol(), ErrMsg(), R_SCN_DISP, SCNINFO_con_offset, SCNINFO_contents, SCNINFO_ev_offset, and SCNINFO_events.
Referenced by Set_Current_Location().
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().
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().
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().
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().
void Set_Current_Location | ( | pSCNINFO | scn, |
BOOL | is_events, | ||
Elf64_Word | ev_ofst | ||
) |
Definition at line 1004 of file em_elf.cxx.
References _leb128_unsigned_encode32(), EK_INCR_LOC, EK_INCR_LOC_EXT, Em_Add_Bytes_To_Scn(), Generate_Addr_Reset(), MAX_EV_SIZE, SCNINFO_con_offset, SCNINFO_contents, SCNINFO_ev_offset, SCNINFO_events, SCNINFO_offset, and Update_Addr_Reset_Size().
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().
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().
BOOL Big_Endian [static] |
Definition at line 97 of file em_elf.cxx.
Referenced by Em_Begin_File().
pSCNINFO Comment_Scn [static] |
Definition at line 84 of file em_elf.cxx.
Elf* Elf_Ptr [static] |
Definition at line 90 of file em_elf.cxx.
Referenced by Create_Elf_Header(), Create_New_Section(), Em_Begin_File(), Em_End_File(), Read_Elf_File(), and Read_Section().
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().
SCNINFO Shstrtab_Info [static] |
Definition at line 78 of file em_elf.cxx.
Definition at line 93 of file em_elf.cxx.
Referenced by Create_Elf_Header(), Create_New_Relocation_Section(), Create_New_Section(), Em_Add_Address_To_Scn(), Em_Add_New_Composite_Rela(), Em_Add_New_Rel(), Em_Add_New_Rela(), Em_Add_New_Symbol(), Em_Add_New_Weak_Symbol(), Em_Begin_File(), Em_Define_Symbol(), Em_Get_Section_Align(), Em_Get_Section_Entsize(), Em_Get_Section_Flags(), Em_Get_Section_Info(), Em_Get_Section_Name(), Em_Get_Section_Type(), Em_Get_Symbol_Name(), Em_Set_sh_info(), Em_Set_sh_link(), Em_Set_Symbol_Binding(), Em_Undefine_Symbol(), Em_Write_Reginfo(), and Read_Elf_File().
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().
SCNINFO Symtab_Info_struct [static] |
Definition at line 80 of file em_elf.cxx.