goloader: the usage of `copy2Slice` here seems to be incorrect, PutInt64 should be used instead

https://github.com/pkujhd/goloader/blob/master/relocate.go#LL138C5-L138C5

copy2Slice used to copy the 8 bytes from *addr to *addr+7 into the TEXT segment, but the correct approach should be to copy the uint64 value addr itself as [8]byte.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 30 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@fumeboy Just to let you know I’m now more happy with the implementation of x86 PCREL relocs in https://github.com/eh-steve/goloader/pull/5, and that branch fixes a bunch of other bugs. There’s still an issue I’d like to fix before merging, and I’d also like to see all 60 (x104) test variations (across OS/arch/±CGo/±dynlink) pass if possible

I think some problems not necessary to be solved. a safe design should not allow user modules to “write” to global variables outside of their own package. If access to specific global variables is required, it should be specifically injected by the linker like this:

package user_module

var will_be_inject *int // inject the value of `pppa.Val` at linktime

func main() {
  a := *will_be_inject + 1
  a = *will_be_inject - 1
  fmt.Println(*will_be_inject)
}

however, this depends on the scene which we want to use goloader.

@eh-steve, I wirte some test code, I found some other things, if a global vaiable is not in current package but it is used in loader, use this golobal varable lead to far address problem,
Almost all instructions need to be processed, not just MOVQ/JMPL it is a big project.

`package main

import ( “fmt”

"github.com/pppa"

)

var a = 1

func main() { a = pppa.Val + 1 a = pppa.Val - 1 pppa.Test() fmt.Println(pppa.Val) } ` The above code has been generated INCQ/SUBQ/MOVQ(89)

@eh-steve @fumeboy ok, I will migrate the bug fix to my repos. thanks

If you encounter a bug,give me a testcase please. thx