mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/ld: allow -r to override rpath when -linkshared
Including having -r "" preventing rpath from being set at all. Change-Id: Ib40d7bf93a6e9ef21985c4a05b5703e4fbd1cd1b Reviewed-on: https://go-review.googlesource.com/8806 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
7e0c11c32f
commit
fd0419b344
3 changed files with 24 additions and 7 deletions
|
|
@ -1818,8 +1818,8 @@ func doelf() {
|
||||||
Elfwritedynent(s, DT_RELENT, ELF32RELSIZE)
|
Elfwritedynent(s, DT_RELENT, ELF32RELSIZE)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rpath != "" {
|
if rpath.val != "" {
|
||||||
Elfwritedynent(s, DT_RUNPATH, uint64(Addstring(dynstr, rpath)))
|
Elfwritedynent(s, DT_RUNPATH, uint64(Addstring(dynstr, rpath.val)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if Thearch.Thechar == '9' {
|
if Thearch.Thechar == '9' {
|
||||||
|
|
|
||||||
|
|
@ -108,12 +108,27 @@ type Arch struct {
|
||||||
Vput func(uint64)
|
Vput func(uint64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Rpath struct {
|
||||||
|
set bool
|
||||||
|
val string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Rpath) Set(val string) error {
|
||||||
|
r.set = true
|
||||||
|
r.val = val
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Rpath) String() string {
|
||||||
|
return r.val
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Thearch Arch
|
Thearch Arch
|
||||||
datap *LSym
|
datap *LSym
|
||||||
Debug [128]int
|
Debug [128]int
|
||||||
Lcsize int32
|
Lcsize int32
|
||||||
rpath string
|
rpath Rpath
|
||||||
Spsize int32
|
Spsize int32
|
||||||
Symsize int32
|
Symsize int32
|
||||||
)
|
)
|
||||||
|
|
@ -935,8 +950,8 @@ func hostlink() {
|
||||||
argv = append(argv, "-o")
|
argv = append(argv, "-o")
|
||||||
argv = append(argv, outfile)
|
argv = append(argv, outfile)
|
||||||
|
|
||||||
if rpath != "" {
|
if rpath.val != "" {
|
||||||
argv = append(argv, fmt.Sprintf("-Wl,-rpath,%s", rpath))
|
argv = append(argv, fmt.Sprintf("-Wl,-rpath,%s", rpath.val))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force global symbols to be exported for dlopen, etc.
|
// Force global symbols to be exported for dlopen, etc.
|
||||||
|
|
@ -955,7 +970,9 @@ func hostlink() {
|
||||||
for _, shlib := range Ctxt.Shlibs {
|
for _, shlib := range Ctxt.Shlibs {
|
||||||
dir, base := filepath.Split(shlib)
|
dir, base := filepath.Split(shlib)
|
||||||
argv = append(argv, "-L"+dir)
|
argv = append(argv, "-L"+dir)
|
||||||
|
if !rpath.set {
|
||||||
argv = append(argv, "-Wl,-rpath="+dir)
|
argv = append(argv, "-Wl,-rpath="+dir)
|
||||||
|
}
|
||||||
base = strings.TrimSuffix(base, ".so")
|
base = strings.TrimSuffix(base, ".so")
|
||||||
base = strings.TrimPrefix(base, "lib")
|
base = strings.TrimPrefix(base, "lib")
|
||||||
argv = append(argv, "-l"+base)
|
argv = append(argv, "-l"+base)
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func Ldmain() {
|
||||||
flag.BoolVar(&Linkshared, "linkshared", false, "link against installed Go shared libraries")
|
flag.BoolVar(&Linkshared, "linkshared", false, "link against installed Go shared libraries")
|
||||||
obj.Flagcount("n", "dump symbol table", &Debug['n'])
|
obj.Flagcount("n", "dump symbol table", &Debug['n'])
|
||||||
obj.Flagstr("o", "outfile: set output file", &outfile)
|
obj.Flagstr("o", "outfile: set output file", &outfile)
|
||||||
obj.Flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath)
|
flag.Var(&rpath, "r", "dir1:dir2:...: set ELF dynamic linker search path")
|
||||||
obj.Flagcount("race", "enable race detector", &flag_race)
|
obj.Flagcount("race", "enable race detector", &flag_race)
|
||||||
obj.Flagcount("s", "disable symbol table", &Debug['s'])
|
obj.Flagcount("s", "disable symbol table", &Debug['s'])
|
||||||
var flagShared int
|
var flagShared int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue