@@ -761,12 +761,12 @@ func asmbMacho(ctxt *Link) {
761
761
ldr := ctxt .loader
762
762
763
763
// must match domacholink below
764
- s1 := ldr .SymSize (ldr .Lookup (".machosymtab " , 0 ))
765
- s2 := ldr .SymSize (ctxt . ArchSyms . LinkEditPLT )
766
- s3 := ldr .SymSize (ctxt . ArchSyms . LinkEditGOT )
767
- s4 := ldr .SymSize (ldr . Lookup ( ".machosymstr" , 0 ) )
768
- s5 := ldr .SymSize (ldr . Lookup ( ".machorebase" , 0 ) )
769
- s6 := ldr .SymSize (ldr .Lookup (".machobind " , 0 ))
764
+ s1 := ldr .SymSize (ldr .Lookup (".machorebase " , 0 ))
765
+ s2 := ldr .SymSize (ldr . Lookup ( ".machobind" , 0 ) )
766
+ s3 := ldr .SymSize (ldr . Lookup ( ".machosymtab" , 0 ) )
767
+ s4 := ldr .SymSize (ctxt . ArchSyms . LinkEditPLT )
768
+ s5 := ldr .SymSize (ctxt . ArchSyms . LinkEditGOT )
769
+ s6 := ldr .SymSize (ldr .Lookup (".machosymstr " , 0 ))
770
770
771
771
if ctxt .LinkMode != LinkExternal {
772
772
ms := newMachoSeg ("__LINKEDIT" , 0 )
@@ -778,13 +778,27 @@ func asmbMacho(ctxt *Link) {
778
778
ms .prot2 = 1
779
779
}
780
780
781
+ if ctxt .LinkMode != LinkExternal && ctxt .IsPIE () {
782
+ ml := newMachoLoad (ctxt .Arch , LC_DYLD_INFO_ONLY , 10 )
783
+ ml .data [0 ] = uint32 (linkoff ) // rebase off
784
+ ml .data [1 ] = uint32 (s1 ) // rebase size
785
+ ml .data [2 ] = uint32 (linkoff + s1 ) // bind off
786
+ ml .data [3 ] = uint32 (s2 ) // bind size
787
+ ml .data [4 ] = 0 // weak bind off
788
+ ml .data [5 ] = 0 // weak bind size
789
+ ml .data [6 ] = 0 // lazy bind off
790
+ ml .data [7 ] = 0 // lazy bind size
791
+ ml .data [8 ] = 0 // export
792
+ ml .data [9 ] = 0 // export size
793
+ }
794
+
781
795
ml := newMachoLoad (ctxt .Arch , LC_SYMTAB , 4 )
782
- ml .data [0 ] = uint32 (linkoff ) /* symoff */
783
- ml .data [1 ] = uint32 (nsortsym ) /* nsyms */
784
- ml .data [2 ] = uint32 (linkoff + s1 + s2 + s3 ) /* stroff */
785
- ml .data [3 ] = uint32 (s4 ) /* strsize */
796
+ ml .data [0 ] = uint32 (linkoff + s1 + s2 ) /* symoff */
797
+ ml .data [1 ] = uint32 (nsortsym ) /* nsyms */
798
+ ml .data [2 ] = uint32 (linkoff + s1 + s2 + s3 + s4 + s5 ) /* stroff */
799
+ ml .data [3 ] = uint32 (s6 ) /* strsize */
786
800
787
- machodysymtab (ctxt )
801
+ machodysymtab (ctxt , linkoff + s1 + s2 )
788
802
789
803
if ctxt .LinkMode != LinkExternal {
790
804
ml := newMachoLoad (ctxt .Arch , LC_LOAD_DYLINKER , 6 )
@@ -800,20 +814,6 @@ func asmbMacho(ctxt *Link) {
800
814
stringtouint32 (ml .data [4 :], lib )
801
815
}
802
816
}
803
-
804
- if ctxt .LinkMode != LinkExternal && ctxt .IsPIE () {
805
- ml := newMachoLoad (ctxt .Arch , LC_DYLD_INFO_ONLY , 10 )
806
- ml .data [0 ] = uint32 (linkoff + s1 + s2 + s3 + s4 ) // rebase off
807
- ml .data [1 ] = uint32 (s5 ) // rebase size
808
- ml .data [2 ] = uint32 (linkoff + s1 + s2 + s3 + s4 + s5 ) // bind off
809
- ml .data [3 ] = uint32 (s6 ) // bind size
810
- ml .data [4 ] = 0 // weak bind off
811
- ml .data [5 ] = 0 // weak bind size
812
- ml .data [6 ] = 0 // lazy bind off
813
- ml .data [7 ] = 0 // lazy bind size
814
- ml .data [8 ] = 0 // export
815
- ml .data [9 ] = 0 // export size
816
- }
817
817
}
818
818
819
819
a := machowrite (ctxt , ctxt .Arch , ctxt .Out , ctxt .LinkMode )
@@ -1018,7 +1018,7 @@ func machosymtab(ctxt *Link) {
1018
1018
}
1019
1019
}
1020
1020
1021
- func machodysymtab (ctxt * Link ) {
1021
+ func machodysymtab (ctxt * Link , base int64 ) {
1022
1022
ml := newMachoLoad (ctxt .Arch , LC_DYSYMTAB , 18 )
1023
1023
1024
1024
n := 0
@@ -1046,7 +1046,7 @@ func machodysymtab(ctxt *Link) {
1046
1046
s1 := ldr .SymSize (ldr .Lookup (".machosymtab" , 0 ))
1047
1047
s2 := ldr .SymSize (ctxt .ArchSyms .LinkEditPLT )
1048
1048
s3 := ldr .SymSize (ctxt .ArchSyms .LinkEditGOT )
1049
- ml .data [12 ] = uint32 (linkoff + s1 ) /* indirectsymoff */
1049
+ ml .data [12 ] = uint32 (base + s1 ) /* indirectsymoff */
1050
1050
ml .data [13 ] = uint32 ((s2 + s3 ) / 4 ) /* nindirectsyms */
1051
1051
1052
1052
ml .data [14 ] = 0 /* extreloff */
@@ -1063,12 +1063,12 @@ func doMachoLink(ctxt *Link) int64 {
1063
1063
ldr := ctxt .loader
1064
1064
1065
1065
// write data that will be linkedit section
1066
- s1 := ldr .Lookup (".machosymtab " , 0 )
1067
- s2 := ctxt . ArchSyms . LinkEditPLT
1068
- s3 := ctxt . ArchSyms . LinkEditGOT
1069
- s4 := ldr . Lookup ( ".machosymstr" , 0 )
1070
- s5 := ldr . Lookup ( ".machorebase" , 0 )
1071
- s6 := ldr .Lookup (".machobind " , 0 )
1066
+ s1 := ldr .Lookup (".machorebase " , 0 )
1067
+ s2 := ldr . Lookup ( ".machobind" , 0 )
1068
+ s3 := ldr . Lookup ( ".machosymtab" , 0 )
1069
+ s4 := ctxt . ArchSyms . LinkEditPLT
1070
+ s5 := ctxt . ArchSyms . LinkEditGOT
1071
+ s6 := ldr .Lookup (".machosymstr " , 0 )
1072
1072
1073
1073
// Force the linkedit section to end on a 16-byte
1074
1074
// boundary. This allows pure (non-cgo) Go binaries
@@ -1087,9 +1087,9 @@ func doMachoLink(ctxt *Link) int64 {
1087
1087
// boundary, codesign_allocate will not need to apply
1088
1088
// any alignment padding itself, working around the
1089
1089
// issue.
1090
- s4b := ldr .MakeSymbolUpdater (s4 )
1091
- for s4b .Size ()% 16 != 0 {
1092
- s4b .AddUint8 (0 )
1090
+ s6b := ldr .MakeSymbolUpdater (s6 )
1091
+ for s6b .Size ()% 16 != 0 {
1092
+ s6b .AddUint8 (0 )
1093
1093
}
1094
1094
1095
1095
size := int (ldr .SymSize (s1 ) + ldr .SymSize (s2 ) + ldr .SymSize (s3 ) + ldr .SymSize (s4 ) + ldr .SymSize (s5 ) + ldr .SymSize (s6 ))
0 commit comments