예제 #1
0
func checkSymtabCrtbegin(t *testing.T, f *ElfFile,
	st SymbolTable, start_off int, start_size int) {
	// crtbegin.o should have:
	// *) U _pnacl_wrapper_start which does a few things and then calls _start
	// *) U __pnacl_irt_init which sets up the __nacl_read_tp function using
	//      the startup_info auxv.
	// *) T __pnacl_start, the entry point for PNaCl programs.
	link_info := GetSymLinkInfo(st)
	ht := SymLinkInfoToHash(link_info, st)
	sym, ok := ht["_pnacl_wrapper_start"]
	ExpectEq(t, true, ok)
	ExpectEq(t, "_pnacl_wrapper_start", sym.St_name)
	ExpectEq(t, uint8(0), sym.St_other)
	ExpectEq(t, elf.SHN_UNDEF, sym.St_shndx)
	ExpectEq(t, uint64(0), sym.St_value)

	sym, ok = ht["__pnacl_init_irt"]
	ExpectEq(t, true, ok)
	ExpectEq(t, "__pnacl_init_irt", sym.St_name)
	ExpectEq(t, uint8(0), sym.St_other)
	ExpectEq(t, elf.SHN_UNDEF, sym.St_shndx)
	ExpectEq(t, uint64(0), sym.St_value)

	text_index := findSectionIndex(".text", f)
	sym, ok = ht["__pnacl_start"]
	ExpectEq(t, true, ok)
	ExpectEq(t, "__pnacl_start", sym.St_name)
	ExpectEq(t, uint8(0), sym.St_other)
	ExpectEq(t, elf.SectionIndex(text_index), sym.St_shndx)
	// Offset relative to the beginning of the file.
	ExpectEq(t, uint64(start_off), sym.St_value)
	ExpectEq(t, uint64(start_size), sym.St_size)
}
예제 #2
0
func readSymbolEntry32(r io.Reader, bo binary.ByteOrder, strtab []byte) (
	SymbolTableEntry, error) {
	st_entry, err1 := readSymbolEntryPrefix(r, bo)
	if err1 == io.EOF {
		return st_entry, err1
	} else if err1 != nil {
		panic("Failed to read symbol table prefix")
	}
	var value, size uint32
	err1 = binary.Read(r, bo, &value)
	err2 := binary.Read(r, bo, &size)
	if err1 != nil || err2 != nil {
		panic("Failed to read st_value, size")
	}
	st_entry.St_value = uint64(value)
	st_entry.St_size = uint64(size)
	var shndx uint16
	err1 = binary.Read(r, bo, &st_entry.St_info)
	err2 = binary.Read(r, bo, &st_entry.St_other)
	err3 := binary.Read(r, bo, &shndx)
	if err1 != nil || err2 != nil || err3 != nil {
		panic("Failed to read st_info, other, or shndx")
	}
	st_entry.St_shndx = elf.SectionIndex(shndx)
	st_entry.St_name = StringFromStrtab(strtab, st_entry.St_name_index)
	return st_entry, nil
}
예제 #3
0
파일: main.go 프로젝트: glycerine/llgo
func symsizes(path string) map[string]float64 {
	m := make(map[string]float64)
	f, err := elf.Open(path)
	if err != nil {
		panic(err.Error())
	}
	syms, err := f.Symbols()
	if err != nil {
		panic(err.Error())
	}
	for _, sym := range syms {
		if sym.Section < elf.SectionIndex(len(f.Sections)) && f.Sections[sym.Section].Name == ".text" {
			m[sym.Name] = float64(sym.Size)
		}
	}
	return m
}