-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unexported func name removing for tiny mode
- Loading branch information
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
internal/linker/patches/0002-add-unexported-function-name-removing.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
From fa9696c29047882eb54344ce911ecf02c7281247 Mon Sep 17 00:00:00 2001 | ||
From: pagran <pagran@protonmail.com> | ||
Date: Mon, 9 Jan 2023 00:03:05 +0100 | ||
Subject: [PATCH] add unexported function name removing | ||
|
||
--- | ||
cmd/link/internal/ld/pcln.go | 27 +++++++++++++++++++++++++++ | ||
1 file changed, 27 insertions(+) | ||
|
||
diff --git a/cmd/link/internal/ld/pcln.go b/cmd/link/internal/ld/pcln.go | ||
index 1ec237ffc8..e1bea2032c 100644 | ||
--- a/cmd/link/internal/ld/pcln.go | ||
+++ b/cmd/link/internal/ld/pcln.go | ||
@@ -321,10 +321,19 @@ func (state *pclntab) generateFuncnametab(ctxt *Link, funcs []loader.Sym) map[lo | ||
return name[:i], "[...]", name[j+1:] | ||
} | ||
|
||
+ garbleIsRemove := os.Getenv("GARBLE_LINK_TINY") == "true" | ||
+ | ||
// Write the null terminated strings. | ||
writeFuncNameTab := func(ctxt *Link, s loader.Sym) { | ||
symtab := ctxt.loader.MakeSymbolUpdater(s) | ||
+ if garbleIsRemove { | ||
+ symtab.AddStringAt(0, "") | ||
+ } | ||
+ | ||
for s, off := range nameOffsets { | ||
+ if garbleIsRemove && off == 0 { | ||
+ continue | ||
+ } | ||
a, b, c := nameParts(ctxt.loader.SymName(s)) | ||
o := int64(off) | ||
o = symtab.AddStringAt(o, a) | ||
@@ -335,7 +344,25 @@ func (state *pclntab) generateFuncnametab(ctxt *Link, funcs []loader.Sym) map[lo | ||
|
||
// Loop through the CUs, and calculate the size needed. | ||
var size int64 | ||
+ | ||
+ if garbleIsRemove { | ||
+ size = 1 // first byte is reserved for empty string used for all non-exportable method names | ||
+ } | ||
+ garbleIsUnexported := func(s loader.Sym) bool { | ||
+ name, _, _ := nameParts(ctxt.loader.SymName(s)) | ||
+ if name[len(name)-1] == '.' { | ||
+ return true | ||
+ } | ||
+ c := name[strings.LastIndexByte(name, '.')+1] | ||
+ return 'a' <= c && c <= 'z' | ||
+ } | ||
+ | ||
walkFuncs(ctxt, funcs, func(s loader.Sym) { | ||
+ if garbleIsRemove && garbleIsUnexported(s) { | ||
+ nameOffsets[s] = 0 // redirect name to empty string | ||
+ return | ||
+ } | ||
+ | ||
nameOffsets[s] = uint32(size) | ||
a, b, c := nameParts(ctxt.loader.SymName(s)) | ||
size += int64(len(a) + len(b) + len(c) + 1) // NULL terminate | ||
-- | ||
2.38.1.windows.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters