@@ -630,24 +630,30 @@ func (ctxt *Link) loadlib() {
630
630
}
631
631
if * flagLibGCC != "none" {
632
632
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 )
651
657
}
652
658
}
653
659
}
0 commit comments