Skip to content

Commit

Permalink
Improve error messages + make sure type deduplication relocation erro…
Browse files Browse the repository at this point in the history
…rs cause a failure
  • Loading branch information
Anonymous committed Apr 24, 2023
1 parent 77f01ac commit 9fbc78a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions jit/jit.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func resolveDependencies(config BuildConfig, workDir, buildDir string, outputFil
sort.Strings(unresolvedList)
return nil, fmt.Errorf("still have %d unresolved external symbols despite building and linking dependencies...: \n%s", len(requiredBy), strings.Join(unresolvedList, "\n"))
}
_ = linker.UnloadStrings()
linker.UnloadStrings()
linker = depsLinker
}
return linker, nil
Expand Down Expand Up @@ -410,7 +410,7 @@ func buildAndLoadDeps(config BuildConfig,
globalMutex.Unlock()

addCGoSymbols(nextUnresolvedSymbols)
_ = linker.UnloadStrings()
linker.UnloadStrings()

if len(nextUnresolvedSymbols) > 0 {
var newSortedDeps []string
Expand Down
13 changes: 6 additions & 7 deletions ld.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,9 @@ func (linker *Linker) deduplicateTypeDescriptors(codeModule *CodeModule, symbolM
}
u := t.uncommon()
prevU := prevT.uncommon()
err := codeModule.patchTypeMethodOffsets(t, u, prevU, patchedTypeMethodsIfn, patchedTypeMethodsTfn)
if err != nil {
return err
err2 := codeModule.patchTypeMethodOffsets(t, u, prevU, patchedTypeMethodsIfn, patchedTypeMethodsTfn)
if err2 != nil {
return err2
}

addr = uintptr(unsafe.Pointer(t))
Expand Down Expand Up @@ -908,7 +908,7 @@ func (linker *Linker) deduplicateTypeDescriptors(codeModule *CodeModule, symbolM
case reloctype.R_ADDROFF, reloctype.R_WEAKADDROFF:
offset := int(addr) - addrBase + loc.Add
if offset > 0x7FFFFFFF || offset < -0x80000000 {
err = fmt.Errorf("symName: %s offset: %d overflows!\n", sym.Name, offset)
err = fmt.Errorf("symName: %s %s offset: %d overflows!\n", objabi.RelocType(loc.Type), sym.Name, offset)
}
byteorder.PutUint32(relocByte[loc.Offset:], uint32(offset))
case reloctype.R_METHODOFF:
Expand All @@ -917,7 +917,7 @@ func (linker *Linker) deduplicateTypeDescriptors(codeModule *CodeModule, symbolM
}
offset := int(addr) - addrBase + loc.Add
if offset > 0x7FFFFFFF || offset < -0x80000000 {
err = fmt.Errorf("symName:%s offset:%d is overflow!\n", sym.Name, offset)
err = fmt.Errorf("symName: %s %s offset: %d overflows!\n", objabi.RelocType(loc.Type), sym.Name, offset)
}
byteorder.PutUint32(relocByte[loc.Offset:], uint32(offset))
case reloctype.R_USETYPE, reloctype.R_USEIFACE, reloctype.R_USEIFACEMETHOD, reloctype.R_ADDRCUOFF, reloctype.R_KEEP:
Expand Down Expand Up @@ -1054,9 +1054,8 @@ func (linker *Linker) UnresolvedExternalSymbolUsers(symbolMap map[string]uintptr
return requiredBy
}

func (linker *Linker) UnloadStrings() error {
func (linker *Linker) UnloadStrings() {
linker.heapStringMap = nil
return nil
}

func Load(linker *Linker, symPtr map[string]uintptr) (codeModule *CodeModule, err error) {
Expand Down
8 changes: 4 additions & 4 deletions relocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (linker *Linker) relocateCALL(addr uintptr, loc obj.Reloc, segment *segment

if offset > 0x7FFFFFFF || offset < -0x80000000 {
if loc.EpilogueSize == 0 {
return fmt.Errorf("relocation epilogue not available but got a >32-bit CALL reloc with offset %d: %s", offset, loc.Sym.Name)
return fmt.Errorf("relocation epilogue not available but got a >32-bit CALL reloc (x86 code: %x) with offset %d: %s", relocByte[loc.Offset-2:loc.Offset+loc.Size], offset, loc.Sym.Name)
}
offset = (segment.codeBase + epilogueOffset) - (addrBase + loc.Offset + loc.Size)
copy(segment.codeByte[epilogueOffset:], x86amd64JMPLcode)
Expand All @@ -154,7 +154,7 @@ func (linker *Linker) relocatePCREL(addr uintptr, loc obj.Reloc, segment *segmen
copy(segment.codeByte[epilogueOffset:epilogueOffset+loc.EpilogueSize], make([]byte, loc.EpilogueSize))
if offset > 0x7FFFFFFF || offset < -0x80000000 {
if loc.EpilogueSize == 0 {
return fmt.Errorf("relocation epilogue not available but got a >32-bit PCREL reloc with offset %d: %s", offset, loc.Sym.Name)
return fmt.Errorf("relocation epilogue not available but got a >32-bit PCREL reloc (x86 code: %x) with offset %d: %s", relocByte[loc.Offset-2:loc.Offset+loc.Size], offset, loc.Sym.Name)
}
relocToEpilogueOffset := (segment.codeBase + epilogueOffset) - (addrBase + loc.Offset + loc.Size)
bytes := relocByte[loc.Offset-2:]
Expand All @@ -175,7 +175,7 @@ func (linker *Linker) relocatePCREL(addr uintptr, loc obj.Reloc, segment *segmen
} else if bytes[1] == x86amd64JMPcode {
opcode = bytes[1]
} else {
return fmt.Errorf("do not support x86 opcode: %x for symbol %s (offset %d)!\n", relocByte[loc.Offset-2:loc.Offset], loc.Sym.Name, offset)
return fmt.Errorf("do not support x86 opcode: %x for symbol %s (offset %d)!\n", relocByte[loc.Offset-2:loc.Offset+loc.Size], loc.Sym.Name, offset)
}
byteorder.PutUint32(relocByte[loc.Offset:], uint32(relocToEpilogueOffset))
switch opcode {
Expand All @@ -201,7 +201,7 @@ func (linker *Linker) relocatePCREL(addr uintptr, loc obj.Reloc, segment *segmen
case x86amd64LEAcode:
putAddressAddOffset(byteorder, segment.codeByte, &epilogueOffset, uint64(addr))
default:
return fmt.Errorf("unexpected x86 opcode %x: %x for symbol %s (offset %d)!\n", opcode, relocByte[loc.Offset-2:loc.Offset], loc.Sym.Name, offset)
return fmt.Errorf("unexpected x86 opcode %x: %x for symbol %s (offset %d)!\n", opcode, relocByte[loc.Offset-2:loc.Offset+loc.Size], loc.Sym.Name, offset)
}

switch opcode {
Expand Down

0 comments on commit 9fbc78a

Please sign in to comment.