Skip to content

Commit c3d3be1

Browse files
committed
cmd/link: try libssp_nonshared.a when looking for "__stack_chk_fail_local"
Update the code that tries to satisfy unresolved references to "__stack_chk_fail_local" to look for "libssp_nonshared.a" in addition to "libc_nonshared.a" (the former archive is the correct place on Alpine). Updates #52919. Updates #54313. Updates #57261. Fixes #58385. Change-Id: Id6cd3ebb4d5388df50a838e6efa5e5b683545b01 Reviewed-on: https://go-review.googlesource.com/c/go/+/466936 Run-TryBot: Than McIntosh <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 48f4728 commit c3d3be1

File tree

1 file changed

+24
-18
lines changed
  • src/cmd/link/internal/ld

1 file changed

+24
-18
lines changed

src/cmd/link/internal/ld/lib.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -630,24 +630,30 @@ func (ctxt *Link) loadlib() {
630630
}
631631
if *flagLibGCC != "none" {
632632
hostArchive(ctxt, *flagLibGCC)
633-
// For glibc systems, the linker setup used by GCC
634-
// looks like
635-
//
636-
// GROUP ( /lib/x86_64-linux-gnu/libc.so.6
637-
// /usr/lib/x86_64-linux-gnu/libc_nonshared.a
638-
// AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
639-
//
640-
// where libc_nonshared.a contains a small set of
641-
// symbols including "__stack_chk_fail_local" and a
642-
// few others. Thus if we are doing internal linking
643-
// and "__stack_chk_fail_local" is unresolved (most
644-
// likely due to the use of -fstack-protector), try
645-
// loading libc_nonshared.a to resolve it.
646-
isunresolved := symbolsAreUnresolved(ctxt, []string{"__stack_chk_fail_local"})
647-
if isunresolved[0] {
648-
if p := ctxt.findLibPath("libc_nonshared.a"); p != "none" {
649-
hostArchive(ctxt, p)
650-
}
633+
}
634+
// For glibc systems, the linker setup used by GCC
635+
// looks like
636+
//
637+
// GROUP ( /lib/x86_64-linux-gnu/libc.so.6
638+
// /usr/lib/x86_64-linux-gnu/libc_nonshared.a
639+
// AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
640+
//
641+
// where libc_nonshared.a contains a small set of
642+
// symbols including "__stack_chk_fail_local" and a
643+
// few others. Thus if we are doing internal linking
644+
// and "__stack_chk_fail_local" is unresolved (most
645+
// likely due to the use of -fstack-protector), try
646+
// loading libc_nonshared.a to resolve it.
647+
//
648+
// On Alpine Linux (musl-based), the library providing
649+
// this symbol is called libssp_nonshared.a.
650+
isunresolved := symbolsAreUnresolved(ctxt, []string{"__stack_chk_fail_local"})
651+
if isunresolved[0] {
652+
if p := ctxt.findLibPath("libc_nonshared.a"); p != "none" {
653+
hostArchive(ctxt, p)
654+
}
655+
if p := ctxt.findLibPath("libssp_nonshared.a"); p != "none" {
656+
hostArchive(ctxt, p)
651657
}
652658
}
653659
}

0 commit comments

Comments
 (0)