Export pageSize and consider "ld.o" files

This commit is contained in:
Gaulthier Gain 2021-12-06 20:13:18 +01:00
parent 6e9f0f5dfe
commit 726e349092
5 changed files with 13 additions and 13 deletions

View file

@ -52,8 +52,8 @@ func (analyser *ElfAnalyser) DisplayMapping() {
_, _ = fmt.Fprintf(w, "%s \t0x%x \t0x%x \t0x%x\t%d\t%f\t%f\n",
name, lib.StartAddr, lib.EndAddr, lib.Size,
lib.NbSymbols, float32(lib.Size)/float32(pageSize),
float32(lib.StartAddr)/float32(pageSize))
lib.NbSymbols, float32(lib.Size)/float32(PageSize),
float32(lib.StartAddr)/float32(PageSize))
}
_ = w.Flush()
}
@ -222,7 +222,7 @@ func (analyser *ElfAnalyser) SplitIntoPagesBySection(elfFile *elf64core.ELF64Fil
}
func CreateNewPage(startAddress uint64, k int, raw []byte) *ElfPage {
byteArray := make([]byte, pageSize)
byteArray := make([]byte, PageSize)
b := raw
if cpd := copy(byteArray, b); cpd == 0 {
u.PrintWarning("0 bytes were copied")
@ -241,9 +241,9 @@ func CreateNewPage(startAddress uint64, k int, raw []byte) *ElfPage {
func (analyser *ElfAnalyser) computePage(elfFile *elf64core.ELF64File, section string, indexSection int) {
offsetTextSection := elfFile.SectionsTable.DataSect[indexSection].Elf64section.FileOffset
k := 0
for i := offsetTextSection; i < offsetTextSection+elfFile.SectionsTable.DataSect[indexSection].Elf64section.Size; i += pageSize {
for i := offsetTextSection; i < offsetTextSection+elfFile.SectionsTable.DataSect[indexSection].Elf64section.Size; i += PageSize {
end := i + pageSize
end := i + PageSize
if end >= uint64(len(elfFile.Raw)) {
end = uint64(len(elfFile.Raw) - 1)
}

View file

@ -13,7 +13,7 @@ import (
"strings"
)
const pageSize = 0x1000
const PageSize = 0x1000
type ElfFileSegment struct {
Filename string

View file

@ -242,7 +242,7 @@ func (analyser *ElfAnalyser) DisplayStatSize(elfFile *elf64core.ELF64File) {
size = s.Elf64section.Size
totalSizeText += size
}
_, _ = fmt.Fprintf(w, "%s\t%d (0x%x)\t%.2f\t%s\n", s.Name, size, size, float32(size)/float32(pageSize), currNext)
_, _ = fmt.Fprintf(w, "%s\t%d (0x%x)\t%.2f\t%s\n", s.Name, size, size, float32(size)/float32(PageSize), currNext)
}
}
@ -250,8 +250,8 @@ func (analyser *ElfAnalyser) DisplayStatSize(elfFile *elf64core.ELF64File) {
_, _ = fmt.Fprintf(w, "Total Size:\n")
_, _ = fmt.Fprintf(w, "Section .text:\t%d (0x%x)\n", totalSizeText, totalSizeText)
_, _ = fmt.Fprintf(w, "All sections:\t%d (0x%x)\n", totalSizeElf, totalSizeElf)
_, _ = fmt.Fprintf(w, "#Pages (.text):\t%d\n", roundPage(float64(totalSizeText)/float64(pageSize)))
_, _ = fmt.Fprintf(w, "#Pages (all sections):\t%d\n", roundPage(float64(totalSizeElf)/float64(pageSize)))
_, _ = fmt.Fprintf(w, "#Pages (.text):\t%d\n", roundPage(float64(totalSizeText)/float64(PageSize)))
_, _ = fmt.Fprintf(w, "#Pages (all sections):\t%d\n", roundPage(float64(totalSizeElf)/float64(PageSize)))
_ = w.Flush()
}

View file

@ -113,7 +113,7 @@ func RunBinaryAnalyser(homeDir string) {
}
}
if foundSection {
if foundSection && len(uk.SectionSplit) > 0 {
path := homeDir + u.SEP + pagesPath
if _, err := os.Stat(path); os.IsNotExist(err) {

View file

@ -73,11 +73,11 @@ func (uk *Unikernel) GetFiles() error {
for _, f := range files {
if f.IsDir() || strings.Contains(f.Name(), makefile) ||
strings.Contains(f.Name(), config) ||
strings.Contains(f.Name(), ldExt) {
strings.Contains(f.Name(), config) {
continue
}
if filepath.Ext(strings.TrimSpace(f.Name())) == objExt &&
if strings.Contains(f.Name(), ldExt) &&
!stringInSlice(f.Name(), uk.IgnoredPlats) {
objFile, err := parseFile(uk.BuildPath, f.Name())
if err != nil {