From eb1fad6ad2921c98da60a787240f37f01b2e322d Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Tue, 10 Nov 2020 18:45:26 -0800 Subject: [PATCH] Delete unused util/* inherited from BoringSSL. --- .gitignore | 23 --- util/ar/ar.go | 154 --------------- util/ar/ar_test.go | 118 ----------- util/ar/testdata/linux/bar.cc.o | Bin 1616 -> 0 bytes util/ar/testdata/linux/foo.c.o | Bin 1464 -> 0 bytes util/ar/testdata/linux/libsample.a | Bin 3328 -> 0 bytes util/ar/testdata/mac/bar.cc.o | Bin 860 -> 0 bytes util/ar/testdata/mac/foo.c.o | Bin 684 -> 0 bytes util/ar/testdata/mac/libsample.a | Bin 1864 -> 0 bytes util/ar/testdata/sample/CMakeLists.txt | 3 - util/ar/testdata/sample/bar.cc | 15 -- util/ar/testdata/sample/foo.c | 7 - util/ar/testdata/windows/bar.cc.obj | Bin 3299 -> 0 bytes util/ar/testdata/windows/foo.c.obj | Bin 1910 -> 0 bytes util/ar/testdata/windows/sample.lib | Bin 5710 -> 0 bytes util/generate-asm-lcov.py | 152 -------------- util/generate-coverage.sh | 60 ------ util/make_prefix_headers.go | 232 ---------------------- util/read_symbols.go | 262 ------------------------- 19 files changed, 1026 deletions(-) delete mode 100644 util/ar/ar.go delete mode 100644 util/ar/ar_test.go delete mode 100644 util/ar/testdata/linux/bar.cc.o delete mode 100644 util/ar/testdata/linux/foo.c.o delete mode 100644 util/ar/testdata/linux/libsample.a delete mode 100644 util/ar/testdata/mac/bar.cc.o delete mode 100644 util/ar/testdata/mac/foo.c.o delete mode 100644 util/ar/testdata/mac/libsample.a delete mode 100644 util/ar/testdata/sample/CMakeLists.txt delete mode 100644 util/ar/testdata/sample/bar.cc delete mode 100644 util/ar/testdata/sample/foo.c delete mode 100644 util/ar/testdata/windows/bar.cc.obj delete mode 100644 util/ar/testdata/windows/foo.c.obj delete mode 100644 util/ar/testdata/windows/sample.lib delete mode 100755 util/generate-asm-lcov.py delete mode 100755 util/generate-coverage.sh delete mode 100644 util/make_prefix_headers.go delete mode 100644 util/read_symbols.go diff --git a/.gitignore b/.gitignore index 7219d6bd3..3b63d5972 100644 --- a/.gitignore +++ b/.gitignore @@ -7,29 +7,6 @@ ssl/test/runner/runner doc/*.html doc/doc.css -util/bot/android_ndk -util/bot/android_tools -util/bot/cmake-linux64 -util/bot/cmake-linux64.tar.gz -util/bot/cmake-mac -util/bot/cmake-mac.tar.gz -util/bot/cmake-win32 -util/bot/cmake-win32.zip -util/bot/golang -util/bot/gyp -util/bot/libcxx -util/bot/libcxxabi -util/bot/llvm-build -util/bot/nasm-win32.exe -util/bot/perl-win32 -util/bot/perl-win32.zip -util/bot/sde-linux64 -util/bot/sde-linux64.tar.bz2 -util/bot/sde-win32 -util/bot/sde-win32.tar.bz2 -util/bot/win_toolchain.json -util/bot/yasm-win32.exe - *.bk *.orig *~ diff --git a/util/ar/ar.go b/util/ar/ar.go deleted file mode 100644 index 756caf53d..000000000 --- a/util/ar/ar.go +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) 2017, Google Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -// ar.go contains functions for parsing .a archive files. - -package ar - -import ( - "bytes" - "errors" - "fmt" - "io" - "strconv" - "strings" -) - -// ParseAR parses an archive file from r and returns a map from filename to -// contents, or else an error. -func ParseAR(r io.Reader) (map[string][]byte, error) { - // See https://en.wikipedia.org/wiki/Ar_(Unix)#File_format_details - const expectedMagic = "!\n" - var magic [len(expectedMagic)]byte - if _, err := io.ReadFull(r, magic[:]); err != nil { - return nil, err - } - if string(magic[:]) != expectedMagic { - return nil, errors.New("ar: not an archive file") - } - - const filenameTableName = "//" - const symbolTableName = "/" - var longFilenameTable []byte - ret := make(map[string][]byte) - - for { - var header [60]byte - if _, err := io.ReadFull(r, header[:]); err != nil { - if err == io.EOF { - break - } - return nil, errors.New("ar: error reading file header: " + err.Error()) - } - - name := strings.TrimRight(string(header[:16]), " ") - sizeStr := strings.TrimRight(string(header[48:58]), "\x00 ") - size, err := strconv.ParseUint(sizeStr, 10, 64) - if err != nil { - return nil, errors.New("ar: failed to parse file size: " + err.Error()) - } - - // File contents are padded to a multiple of two bytes - storedSize := size - if storedSize%2 == 1 { - storedSize++ - } - - contents := make([]byte, storedSize) - if _, err := io.ReadFull(r, contents); err != nil { - return nil, errors.New("ar: error reading file contents: " + err.Error()) - } - contents = contents[:size] - - switch { - case name == filenameTableName: - if longFilenameTable != nil { - return nil, errors.New("ar: two filename tables found") - } - longFilenameTable = contents - continue - - case name == symbolTableName: - continue - - case len(name) > 1 && name[0] == '/': - if longFilenameTable == nil { - return nil, errors.New("ar: long filename reference found before filename table") - } - - // A long filename is stored as "/" followed by a - // base-10 offset in the filename table. - offset, err := strconv.ParseUint(name[1:], 10, 64) - if err != nil { - return nil, errors.New("ar: failed to parse filename offset: " + err.Error()) - } - if offset > uint64((^uint(0))>>1) { - return nil, errors.New("ar: filename offset overflow") - } - - if int(offset) > len(longFilenameTable) { - return nil, errors.New("ar: filename offset out of bounds") - } - - filename := longFilenameTable[offset:] - // Windows terminates filenames with NUL characters, - // while sysv/GNU uses /. - if i := bytes.IndexAny(filename, "/\x00"); i < 0 { - return nil, errors.New("ar: unterminated filename in table") - } else { - filename = filename[:i] - } - - name = string(filename) - - default: - name = strings.TrimRight(name, "/") - } - - // Post-processing for BSD: - // https://en.wikipedia.org/wiki/Ar_(Unix)#BSD_variant - // - // If the name is of the form #1/XXX, XXX identifies the length of the - // name, and the name itself is stored as a prefix of the data, possibly - // null-padded. - - var namelen uint - n, err := fmt.Sscanf(name, "#1/%d", &namelen) - if err == nil && n == 1 && len(contents) >= int(namelen) { - name = string(contents[:namelen]) - contents = contents[namelen:] - - // Names can be null padded; find the first null (if any). Note that - // this also handles the case of a null followed by non-null - // characters. It's not clear whether those can ever show up in - // practice, but we might as well handle them in case they can show - // up. - var null int - for ; null < len(name); null++ { - if name[null] == 0 { - break - } - } - name = name[:null] - } - - if name == "__.SYMDEF" || name == "__.SYMDEF SORTED" { - continue - } - - ret[name] = contents - } - - return ret, nil -} diff --git a/util/ar/ar_test.go b/util/ar/ar_test.go deleted file mode 100644 index ef37d795d..000000000 --- a/util/ar/ar_test.go +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (c) 2018, Google Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -package ar - -import ( - "bytes" - "flag" - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -var testDataDir = flag.String("testdata", "testdata", "The path to the test data directory.") - -type arTest struct { - name string - in string - out map[string]string - // allowPadding is true if the contents may have trailing newlines at end. - // On macOS, ar calls ranlib which pads all inputs up to eight bytes with - // newlines. Unlike ar's native padding up to two bytes, this padding is - // included in the size field, so it is not removed when decoding. - allowPadding bool -} - -func (test *arTest) Path(file string) string { - return filepath.Join(*testDataDir, test.name, file) -} - -func removeTrailingNewlines(in []byte) []byte { - for len(in) > 0 && in[len(in)-1] == '\n' { - in = in[:len(in)-1] - } - return in -} - -var arTests = []arTest{ - { - "linux", - "libsample.a", - map[string]string{ - "foo.c.o": "foo.c.o", - "bar.cc.o": "bar.cc.o", - }, - false, - }, - { - "mac", - "libsample.a", - map[string]string{ - "foo.c.o": "foo.c.o", - "bar.cc.o": "bar.cc.o", - }, - true, - }, - { - "windows", - "sample.lib", - map[string]string{ - "CMakeFiles\\sample.dir\\foo.c.obj": "foo.c.obj", - "CMakeFiles\\sample.dir\\bar.cc.obj": "bar.cc.obj", - }, - false, - }, -} - -func TestAR(t *testing.T) { - for _, test := range arTests { - t.Run(test.name, func(t *testing.T) { - in, err := os.Open(test.Path(test.in)) - if err != nil { - t.Fatalf("opening input failed: %s", err) - } - defer in.Close() - - ret, err := ParseAR(in) - if err != nil { - t.Fatalf("reading input failed: %s", err) - } - - for file, contentsPath := range test.out { - expected, err := ioutil.ReadFile(test.Path(contentsPath)) - if err != nil { - t.Fatalf("error reading %s: %s", contentsPath, err) - } - got, ok := ret[file] - if test.allowPadding { - got = removeTrailingNewlines(got) - expected = removeTrailingNewlines(got) - } - if !ok { - t.Errorf("file %s missing from output", file) - } else if !bytes.Equal(got, expected) { - t.Errorf("contents for file %s did not match", file) - } - } - - for file, _ := range ret { - if _, ok := test.out[file]; !ok { - t.Errorf("output contained unexpected file %q", file) - } - } - }) - } -} diff --git a/util/ar/testdata/linux/bar.cc.o b/util/ar/testdata/linux/bar.cc.o deleted file mode 100644 index 92e83a9a1108df10391db6c58497cd9bf06cdd2d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1616 zcmbtTL2DC16n>l4R&A6h9t!o4lPKCTn+h#OWRtLo%F>8!Km}Pg>z0b$UD-?|deDO) zddp7|{3Bijk9rsCd%N?}WjbE;3p4L~-@Nx`=4JN1=l5%t1q=)B!m-CHz(f0(y9ITj z4l6La_xbz$*;g_@NG>K6V9@JrH?NJx(^O8In_@$>*4vxY!gby`TcUOQdMOvh;Bsle zdiw~hS;JbZFQ1v?L9U=qgRo3f=R)ISt#^K@ivj4;+8xpn7ir>kzg#ED1iIrX_;qAj zvyB}9u<>Vtjg?HWVaX(8mEtBR)@(R^LZdrgs+@;2>q=+8xI1dMa5Qk}@K7-6_y3~9 zILt*9k%8dpjG?TFy?2OhYGK^k=D8l1|U_ZyU@V@_R zn^=I}rv7qV)CjAkS2Y8!RZx`?K9foq09%L)EEpJ$9(_Rl63EpA_SB@B;Ub{Rc=) z{r_UcHoaQ?8y*|Eu16lwegAmE=^Q-=DrSQ~pnt|D=*j HRL}ndEL4Ek diff --git a/util/ar/testdata/linux/foo.c.o b/util/ar/testdata/linux/foo.c.o deleted file mode 100644 index 6423c1d49bc09ac51932452bb8e306243fc83141..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1464 zcmb_bL2DCH5S~r6Ra+$$4?;bx7g4m2L@O;l$fhBQ$YM|%(1R?yaZAA@3!4p85%nZ^ z>(A-kKj9w`ym}Yvd~e^-=j-Moe#?6^^X<&Md9$;hx?!*8c_i@Y5uIAX5*^o0^+2lu zttkzMH8<~+w9ax(??m4F z=j0tWy!F-P3rAeQ4d$_cHEiuGjW4y%<)x4vU@rh_KS#e#s$SPCZ$?z-rwVn>RE0V% zRneSfc>#a^3=hw%Rz3QT%&qWhobe{Qxqxpi;Aub0)CfC8{cy0`4x>S@_oBNO?X`Eq zZba!}k>=BQ9L?TMl59*#oa0!j6gR)b>-R|s=m2=sD7?=)fbp z%hPeJ3NC=uo4ANcC9@f+Q8t;RQ|6{wk*faF;l`|pM{h}K_w*pz&*Mp|5Bm?B&p9wF z?w1Uh1LS*@R_QA`kKMNLe2 zeYULfp2BJ`0OWCO0d&VS)}jdNUK89$3-%Z?Zs;|F)^pDf?9rvD5meiuA3u%4$_oJ0 z6~2h}w%>D$`|CTFOC=eRT`DJxwc7i(Qmc05a=3LuIhclhiBW)^u6^E-tONbf2g|oU ze)~?coVFi-hWWX@80wBicg`1goPyKE#;(8xSLAiuw zO25KcrW_&~!I9Q8DjE3g44irZCe=~DJJS1#>^L1CEu%&HXsM{4qkp_$EOag+v$yd1 z2q&GxdX9rSMDz;L;CuSldlAY5S>#o;zx3Yf{Nf3wht5VIadQnHI@B7;mVOcN(AM`XMe1XT z_v;=n{4LzSL&4w2Cc6MUPpiz^g0&{w+W#symoA?Qt-dob2_1=SS#6UgRA6yi@bAGa^M7KRLGT^3muoq1oUZX6n% zL2?9$qe?nJyhhtFCczUZ%=2r)0Xi^>?m+lf2gk+ltfXf5-J0@o`N#N6dFh#rpz7rs fp;z+L^w1_nlE1|R{%EI_;i#83cYAdm!N3lJX%D1eIJfU1GtHx zttf%8A^Z^6h!6xH#u9)sK<0tm;=#ng07M{81Bilw`1s`f+=9g9lK9fR^31%H_;?=| zm>h_PnWF#|d;v5M-zEF9?J5kP1RQI-kA( zX#x|mhhh4m;Q|c;m?#5-2$acK6~w?;A;2iW!_F}Qs7eJW4szdy{}2ERR|ZEufi@;* zUN)#ckPm^%byfM4@@wrMR|!i M@x_(7N%=Vp0FaM5A^-pY diff --git a/util/ar/testdata/mac/libsample.a b/util/ar/testdata/mac/libsample.a deleted file mode 100644 index b7d8eb5ce0ff38cd7f9f1c5758ef4904865c4889..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1864 zcmbtVJ#Q015FH0dA_IvFkN_dE2pS5TJAcG35DLPMQt%lY6i}kIbDZT!@m=IN5U5fh zB)a^Bl$0qckwpWL5URON{k_Nvw>^qIK8b z=tk?vuT|!2ec!H9vS2)}Wp;!JKXx|RSkc-G+h|Z%uLp0IgI8KVFnzY?7Dvg(9`Lx9 zd4Nf&2G+)F?YDHZgSJOITJNvVk-%xO*k$6B#g^0soYA8 zw7YY&-^|YJ?#+(+>Uuc6@y0X9)&sPFO;OcgidAIJCv+flTyVdfu^|Xim8A;l$hbRm zu@2y4#JzEsEm?Z9gHiLphJr0%W?PO4ug|n`S0au(V7< zHWC&yE!vKRDQEK;L=?1)nux{aSvH_$nCZx)s%9iovJq93sGfQbMA#n^rU1Ty%@Bko zP4LFJrWm@ZPg~&~V{PHlyrpHe1za>7)3bTBXuu|jgp$dkl9VmW&{73-0k)uQhGp{1 z@Js7aDq9(#5#7XLf(@-B0BReoC62|EYiNy57Dz`{cR{~!q$wfv9w&7^P)JeXW2j@ zr&yYv<9>w^UV+N}>h>XM9U}5?C+7h03N6yw8*sc2$GdUle&9&{?m@?Q!Me~e`nBd9 zM3EI)&Ptkk!BAL_dp@ui;eA!ZMNzkpoh2D`p=$4Ks9MMJr1m(fNtM+8bxTCCxH~Cl zEK)3aJb?Q9?p$9K9X}}Y?kepROgZgyp%+ys~$Fuo1 z6ugzT<4VCwidkJP_#+{g>Z$;Gmf;%yKlENu9taBGztes0N@Lr}*58Lu@B8)rF9EKi zyayX7Vxmx5^A5BrJ1=Qjn?q2%ha=GvcS8+6KBK8)mHq(32Gd4#vbkvwFeRL1h^zoFZ)^H$I1u`6=cOCp zwe6DMZGC-pDbl@nPXF=j!GQ;sfY!t!srnU2vmkq#3k|tl=IiiKsxo2&TdbgtF81R>cR00MBI(_11Uwa-; z!lea=;TX=pf<5i5ZHGjkVx#+MV|an+6p~cm1_VNvZjrq^0OwIk#4+G6D+&K!T9>(w z?Lh#dz9N%q%YZQG%$J6GT>1&BJ^JS@X5{3ITZ2et^@$`M={bD(s13a}Bsn$_OAh5U zt5-G|@UQWif~D$nIfxW;b6QS~(4C0z(%WVoF?ZzF)*Y=XkY#>&+g|36x2^vGM(W+{ diff --git a/util/ar/testdata/windows/foo.c.obj b/util/ar/testdata/windows/foo.c.obj deleted file mode 100644 index 9b4aad7a4294ae0b4a2e242c96c55a574441869e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1910 zcmcIlO>7fK6n>ixp(Lf)5LdJmy0}IZiEg8$Ko#Y%#DO@%Cg3=r!lHQX-N2T$*VS8=B<8m2~4;Cv;S!$z#8yH)*YkhjTn3gZD@=N!HDbT2*|oos2)rV1Yc&6 za~Yc@`UtuN1tQ&?mkW5KXiRcWfH9tD9Q6{Va)7NvBZ5vgkt37_Y!d9s%SUz1(-_3M z53uj!oB&mzO_3{M-iP>cH}Vc}E``8&j#o_dW%dPg$={F28RtCQ5-1Txk%^ZJ^UfgW z{M)?Zp~LRxZvuCaLhDz~se#S77fJfMXWRCzgXvtlue&pz8Q7D|=6d2`v_IXmb8BYX zKwKghFR}fG%>W@vzLK5lpldj;s%s;rUNFjP($)>NU^`~{pzB&{)iW(sb5zf8Jvt86 z)k+l$8CBEL)nrCHY-~3z!{xZFn~pkc+j3F13*SR0bVVT#@Bmgo1SU+OrZZ;Iv0Z!E zlfKMukoqg0Su&5|no`m(RnVd1$C|+yH$X3omEt9#dyQfHoCXo7g;_$Z0h-zyDmY*lOqygFHj!<~x5({shGAEerD)N0EXYS_ z3UFdw?CuUR`h0q_UCig_zKZQzb#wL0?dS zgO%4)KeZeSbl^`ZVphtgK4CTrZ{AQu%CMn%a$DOu0mgi!zU)yfqCkZ&EcGRi%8@9{ zA~pQB>&qRL7*U{t7Z$m$)X{8Fpd==bzh9Vny}(`YEaBIJhOeq7gwUG_q!9=qX$_zn z5)UDX^v;d|pcR^+zNAu`i2~gdN#5>w=v&kWC&D;TUtsZp;VepT+H<@0^L12Qy0~T> zU}cn-TYQduEjn>u{5=5l@-gH1vv~2P*!&3JoppfEVjPg`O7RjlE5*MrC>Krq@fc27 zvxeLsN(I}3p=>TW)K@mWZp}6P(ZHdqr`t!$kf@fAm}NadXP;od7-oj1)b_~GU~26L F@*khFPow|< diff --git a/util/ar/testdata/windows/sample.lib b/util/ar/testdata/windows/sample.lib deleted file mode 100644 index efeebb24e5427b0bccc5d1ad7755d3dd964f15ea..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5710 zcmcIoZ){sv6+bUd!{(ATX&VG|tX^>21y;vSnl$mM@shM@swOK-(rxWL+0XWC@~Goy zJwK;^RzX<>`!GR}XvT*Xp=lru!T2K~L_|MK>V$^I2M~OKfeO-!Hlzx+b(Mf3jq|(r zKKni6QYX-3-FNRh?|1J1d+zV}-aUqsn}0Ce8wpBcU{`-)D6wmJD5#IC*MVVAp9vFD zh)6pl(_I%nHDfQBaF^%+Y5Z%URkdC>>|2f6-}=~;aoilY3T8P~HWo?+GnTiU6b~$x%f;;MXQ(lN zM;(*j!@b^Qsv*hN&UES+Rk&FX#|unX6vopDoNJzR zqYFh(H^7AqSF((XSg=kJ`gA6CGHDweKfkRoo>r&09xDZLALfrMjQf?sw(+~b zIc_d`VCtx6i_h&mA6=Xv7`on}>oMSFgSf4X*-?+n%^xoh?h>|mOmIplOjXIdotLY3 z@4oSo!;`a<2S$_KQ!|f@P0#M_4r&ig?tN%vYTrzEq?L`|;q*4AW2AMWuCZk5aM^Uq zsl2gh<+ElnHD>3{RMvK^;#|30NL5^`kTRTUKM8sR@EZSbr`A0ebAm^eVoTI2H13T6{hZ~63iZCGrf`7f9#TEaxsxM3N8$5 zJsxNK2i9(%Osalhu?Qz;vBzAlWiY5$r`lSxq(Ps1m;j(DRw+4vB>iSy$%VXAOFY3=V`_5ZjB=MLy_evyvX*<7y4YtxJ`N?jLOIiz)vJx*yR|~cEp(LFl za){?3QRX>hCW&Fo5}JZD4~e?q_Cw-}Ea3~5n!Tk@mxbe}4UG zFZb%xb9_z4to)L-PJ91-w5}gB4L25#e?_CSQsXCLSgep1_spxgpM>EO3~8WY7;#Pf z1Pr4Lfn(Q6%tyX3b0H1%3pGCX=j+Q745nR^2!F*r>q#p?1A)C1Pt(h(D;cU51RXoZ;;d3*Pf6iJUvD!FyyC&pnxF_tB=z0r=R4N z@Z_{A2#hFyfuERJSr1e{;Dr4tF@hi}A_;yQ(tyUwNs+Td^tyT%81mCf;BRL2wz3i! ziup(;xMfJ2P~U4=8#gV&n0+T*(5@VL@alWm~ zrXoK2hQi=o$o~)@y}%Wiw=+Jf#oh>yD6_WkNZk94Vj8Tg7gGqYDJDex&w-dGB46vD zqk)*_R6sm5JDa9hit6*d?6}a-XYD|LuFzKf2uh(zU*OUp=$`=aT#AXnxJy zM@(RV_pE2n{adaQdvHDdL6ySHy*%A!RSFZfN+Ui4w|raT;Q*g$g1>x-J0khZ7A}Fx zF@N##7A&wQU=@<9$Py0gMxpZ%$U*aP%xWU}iN{7(&i92fnaex7j&Aw!$KE-zH2u%> z&c%-`Pi@HVzq0$KO)sXVpW5-|%g!4f3-NNVz8V{8{Xer2IKAN6UK<<1oWa5U^tp@I zygMBf`R4XhI+WB30?mhi+?0Krxa zHDDUp-f*jZg=c@rnUXy!Umc6sudG(bB0O4z{&Np~uJ~pwqRdGCV@?o=botam)-K4K R{}wy|Y*F3lD6Zzp{x|0|mFNHf diff --git a/util/generate-asm-lcov.py b/util/generate-asm-lcov.py deleted file mode 100755 index 257ae841c..000000000 --- a/util/generate-asm-lcov.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/python -# Copyright (c) 2016, Google Inc. -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -import os -import os.path -import subprocess -import sys - -# The LCOV output format for each source file is: -# -# SF: -# DA:, -# ... -# end_of_record -# -# The can either be 0 for an unexecuted instruction or a -# value representing the number of executions. The DA line should be omitted -# for lines not representing an instruction. - -SECTION_SEPERATOR = '-' * 80 - -def is_asm(l): - """Returns whether a line should be considered to be an instruction.""" - l = l.strip() - # Empty lines - if l == '': - return False - # Comments - if l.startswith('#'): - return False - # Assembly Macros - if l.startswith('.'): - return False - # Label - if l.endswith(':'): - return False - return True - -def merge(callgrind_files, srcs): - """Calls callgrind_annotate over the set of callgrind output - |callgrind_files| using the sources |srcs| and merges the results - together.""" - out = '' - for file in callgrind_files: - data = subprocess.check_output(['callgrind_annotate', file] + srcs) - out += '%s\n%s\n' % (data, SECTION_SEPERATOR) - return out - -def parse(filename, data, current): - """Parses an annotated execution flow |data| from callgrind_annotate for - source |filename| and updates the current execution counts from |current|.""" - with open(filename) as f: - source = f.read().split('\n') - - out = current - if out == None: - out = [0 if is_asm(l) else None for l in source] - - # Lines are of the following formats: - # -- line: Indicates that analysis continues from a different place. - # Ir : Indicates the start of a file. - # => : Indicates a call/jump in the control flow. - # : Indicates that the line has been executed that many times. - line = None - for l in data: - l = l.strip() + ' ' - if l.startswith('-- line'): - line = int(l.split(' ')[2]) - 1 - elif l.strip() == 'Ir': - line = 0 - elif line != None and l.strip() and '=>' not in l and 'unidentified lines' not in l: - count = l.split(' ')[0].replace(',', '').replace('.', '0') - instruction = l.split(' ', 1)[1].strip() - if count != '0' or is_asm(instruction): - if out[line] == None: - out[line] = 0 - out[line] += int(count) - line += 1 - - return out - - -def generate(data): - """Parses the merged callgrind_annotate output |data| and generates execution - counts for all annotated files.""" - out = {} - data = [p.strip() for p in data.split(SECTION_SEPERATOR)] - - - # Most sections are ignored, but a section with: - # User-annotated source: - # precedes a listing of execution count for that . - for i in range(len(data)): - if 'User-annotated source' in data[i] and i < len(data) - 1: - filename = data[i].split(':', 1)[1].strip() - res = data[i + 1] - if filename not in out: - out[filename] = None - if 'No information' in res: - res = [] - else: - res = res.split('\n') - out[filename] = parse(filename, res, out[filename]) - return out - -def output(data): - """Takes a dictionary |data| of filenames and execution counts and generates - a LCOV coverage output.""" - out = '' - for filename, counts in data.iteritems(): - out += 'SF:%s\n' % (os.path.abspath(filename)) - for line, count in enumerate(counts): - if count != None: - out += 'DA:%d,%s\n' % (line + 1, count) - out += 'end_of_record\n' - return out - -if __name__ == '__main__': - if len(sys.argv) != 3: - print '%s ' % (__file__) - sys.exit() - - cg_folder = sys.argv[1] - build_folder = sys.argv[2] - - cg_files = [] - for (cwd, _, files) in os.walk(cg_folder): - for f in files: - if f.startswith('callgrind.out'): - cg_files.append(os.path.abspath(os.path.join(cwd, f))) - - srcs = [] - for (cwd, _, files) in os.walk(build_folder): - for f in files: - fn = os.path.join(cwd, f) - if fn.endswith('.S'): - srcs.append(fn) - - annotated = merge(cg_files, srcs) - lcov = generate(annotated) - print output(lcov) diff --git a/util/generate-coverage.sh b/util/generate-coverage.sh deleted file mode 100755 index 2fbe6b837..000000000 --- a/util/generate-coverage.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh -# Copyright (c) 2016, Google Inc. -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -set -xe - -SRC=$PWD - -BUILD=$(mktemp -d '/tmp/boringssl.XXXXXX') -BUILD_SRC=$(mktemp -d '/tmp/boringssl-src.XXXXXX') -LCOV=$(mktemp -d '/tmp/boringssl-lcov.XXXXXX') - -if [ -n "$1" ]; then - LCOV=$(readlink -f "$1") - mkdir -p "$LCOV" -fi - -cd "$BUILD" -cmake "$SRC" -GNinja -DCMAKE_C_FLAGS='-fprofile-arcs -ftest-coverage' \ - -DCMAKE_CXX_FLAGS='-fprofile-arcs -ftest-coverage' -DCMAKE_ASM_FLAGS='-Wa,-g' -ninja - -cp -r "$SRC/crypto" "$SRC/decrepit" "$SRC/include" "$SRC/ssl" "$SRC/tool" \ - "$BUILD_SRC" -cp -r "$BUILD"/* "$BUILD_SRC" -mkdir "$BUILD/callgrind/" - -cd "$SRC" -go run "$SRC/util/all_tests.go" -build-dir "$BUILD" -callgrind -num-workers 16 -util/generate-asm-lcov.py "$BUILD/callgrind" "$BUILD" > "$BUILD/asm.info" - -go run "util/all_tests.go" -build-dir "$BUILD" - -cd "$SRC/ssl/test/runner" -go test -shim-path "$BUILD/ssl/test/bssl_shim" -num-workers 1 - -cd "$LCOV" -lcov -c -d "$BUILD" -b "$BUILD" -o "$BUILD/lcov.info" -lcov -r "$BUILD/lcov.info" "*_test.c" -o "$BUILD/lcov-1.info" -lcov -r "$BUILD/lcov-1.info" "*_test.cc" -o "$BUILD/lcov-2.info" -cat "$BUILD/lcov-2.info" "$BUILD/asm.info" > "$BUILD/final.info" -sed -i "s;$BUILD;$BUILD_SRC;g" "$BUILD/final.info" -sed -i "s;$SRC;$BUILD_SRC;g" "$BUILD/final.info" -genhtml -p "$BUILD_SRC" "$BUILD/final.info" - -rm -rf "$BUILD" -rm -rf "$BUILD_SRC" - -xdg-open index.html diff --git a/util/make_prefix_headers.go b/util/make_prefix_headers.go deleted file mode 100644 index b536f14ce..000000000 --- a/util/make_prefix_headers.go +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright (c) 2018, Google Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -// This program takes a file containing newline-separated symbols, and generates -// boringssl_prefix_symbols.h, boringssl_prefix_symbols_asm.h, and -// boringssl_prefix_symbols_nasm.inc. These header files can be used to build -// BoringSSL with a prefix for all symbols in order to avoid symbol name -// conflicts when linking a project with multiple copies of BoringSSL; see -// BUILDING.md for more details. - -// TODO(joshlf): For platforms which support it, use '#pragma redefine_extname' -// instead of a custom macro. This avoids the need for a custom macro, but also -// ensures that our renaming won't conflict with symbols defined and used by our -// consumers (the "HMAC" problem). An example of this approach can be seen in -// IllumOS' fork of OpenSSL: -// https://github.com/joyent/illumos-extra/blob/master/openssl1x/sunw_prefix.h - -package main - -import ( - "bufio" - "flag" - "fmt" - "os" - "path/filepath" - "strings" -) - -var out = flag.String("out", ".", "Path to a directory where the outputs will be written") - -// Read newline-separated symbols from a file, ignoring any comments started -// with '#'. -func readSymbols(path string) ([]string, error) { - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() - scanner := bufio.NewScanner(f) - var ret []string - for scanner.Scan() { - line := scanner.Text() - if idx := strings.IndexByte(line, '#'); idx >= 0 { - line = line[:idx] - } - line = strings.TrimSpace(line) - if len(line) == 0 { - continue - } - ret = append(ret, line) - } - if err := scanner.Err(); err != nil { - return nil, err - } - return ret, nil -} - -func writeCHeader(symbols []string, path string) error { - f, err := os.Create(path) - if err != nil { - return err - } - defer f.Close() - - if _, err := f.WriteString(`// Copyright (c) 2018, Google Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -// BORINGSSL_ADD_PREFIX pastes two identifiers into one. It performs one -// iteration of macro expansion on its arguments before pasting. -#define BORINGSSL_ADD_PREFIX(a, b) BORINGSSL_ADD_PREFIX_INNER(a, b) -#define BORINGSSL_ADD_PREFIX_INNER(a, b) a ## _ ## b - -`); err != nil { - return err - } - - for _, symbol := range symbols { - if _, err := fmt.Fprintf(f, "#define %s BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, %s)\n", symbol, symbol); err != nil { - return err - } - } - - return nil -} - -func writeASMHeader(symbols []string, path string) error { - f, err := os.Create(path) - if err != nil { - return err - } - defer f.Close() - - if _, err := f.WriteString(`// Copyright (c) 2018, Google Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -#if !defined(__APPLE__) -#include -#else -// On iOS and macOS, we need to treat assembly symbols differently from other -// symbols. The linker expects symbols to be prefixed with an underscore. -// Perlasm thus generates symbol with this underscore applied. Our macros must, -// in turn, incorporate it. -#define BORINGSSL_ADD_PREFIX_MAC_ASM(a, b) BORINGSSL_ADD_PREFIX_INNER_MAC_ASM(a, b) -#define BORINGSSL_ADD_PREFIX_INNER_MAC_ASM(a, b) _ ## a ## _ ## b - -`); err != nil { - return err - } - - for _, symbol := range symbols { - if _, err := fmt.Fprintf(f, "#define _%s BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, %s)\n", symbol, symbol); err != nil { - return err - } - } - - _, err = fmt.Fprintf(f, "#endif\n") - return nil -} - -func writeNASMHeader(symbols []string, path string) error { - f, err := os.Create(path) - if err != nil { - return err - } - defer f.Close() - - // NASM uses a different syntax from the C preprocessor. - if _, err := f.WriteString(`; Copyright (c) 2018, Google Inc. -; -; Permission to use, copy, modify, and/or distribute this software for any -; purpose with or without fee is hereby granted, provided that the above -; copyright notice and this permission notice appear in all copies. -; -; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -; SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -; OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -; 32-bit Windows adds underscores to C functions, while 64-bit Windows does not. -%ifidn __OUTPUT_FORMAT__, win32 -`); err != nil { - return err - } - - for _, symbol := range symbols { - if _, err := fmt.Fprintf(f, "%%xdefine _%s _ %%+ BORINGSSL_PREFIX %%+ _%s\n", symbol, symbol); err != nil { - return err - } - } - - if _, err := fmt.Fprintf(f, "%%else\n"); err != nil { - return err - } - - for _, symbol := range symbols { - if _, err := fmt.Fprintf(f, "%%xdefine %s BORINGSSL_PREFIX %%+ _%s\n", symbol, symbol); err != nil { - return err - } - } - - if _, err := fmt.Fprintf(f, "%%endif\n"); err != nil { - return err - } - - return nil -} - -func main() { - flag.Parse() - if flag.NArg() != 1 { - fmt.Fprintf(os.Stderr, "Usage: %s [-out OUT] SYMBOLS\n", os.Args[0]) - os.Exit(1) - } - - symbols, err := readSymbols(flag.Arg(0)) - if err != nil { - fmt.Fprintf(os.Stderr, "Error reading symbols: %s\n", err) - os.Exit(1) - } - - if err := writeCHeader(symbols, filepath.Join(*out, "boringssl_prefix_symbols.h")); err != nil { - fmt.Fprintf(os.Stderr, "Error writing boringssl_prefix_symbols.h: %s\n", err) - os.Exit(1) - } - - if err := writeASMHeader(symbols, filepath.Join(*out, "boringssl_prefix_symbols_asm.h")); err != nil { - fmt.Fprintf(os.Stderr, "Error writing boringssl_prefix_symbols_asm.h: %s\n", err) - os.Exit(1) - } - - if err := writeNASMHeader(symbols, filepath.Join(*out, "boringssl_prefix_symbols_nasm.inc")); err != nil { - fmt.Fprintf(os.Stderr, "Error writing boringssl_prefix_symbols_nasm.inc: %s\n", err) - os.Exit(1) - } - -} diff --git a/util/read_symbols.go b/util/read_symbols.go deleted file mode 100644 index 791ea5d12..000000000 --- a/util/read_symbols.go +++ /dev/null @@ -1,262 +0,0 @@ -// Copyright (c) 2018, Google Inc. -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION -// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -// read_symbols scans one or more .a files and, for each object contained in -// the .a files, reads the list of symbols in that object file. -package main - -import ( - "bytes" - "debug/elf" - "debug/macho" - "debug/pe" - "flag" - "fmt" - "os" - "runtime" - "sort" - "strings" - - "boringssl.googlesource.com/boringssl/util/ar" -) - -const ( - ObjFileFormatELF = "elf" - ObjFileFormatMachO = "macho" - ObjFileFormatPE = "pe" -) - -var ( - outFlag = flag.String("out", "-", "File to write output symbols") - objFileFormat = flag.String("obj-file-format", defaultObjFileFormat(runtime.GOOS), "Object file format to expect (options are elf, macho, pe)") -) - -func defaultObjFileFormat(goos string) string { - switch goos { - case "linux": - return ObjFileFormatELF - case "darwin": - return ObjFileFormatMachO - case "windows": - return ObjFileFormatPE - default: - // By returning a value here rather than panicking, the user can still - // cross-compile from an unsupported platform to a supported platform by - // overriding this default with a flag. If the user doesn't provide the - // flag, we will panic during flag parsing. - return "unsupported" - } -} - -func printAndExit(format string, args ...interface{}) { - s := fmt.Sprintf(format, args...) - fmt.Fprintln(os.Stderr, s) - os.Exit(1) -} - -func main() { - flag.Parse() - if flag.NArg() < 1 { - printAndExit("Usage: %s [-out OUT] [-obj-file-format FORMAT] ARCHIVE_FILE [ARCHIVE_FILE [...]]", os.Args[0]) - } - archiveFiles := flag.Args() - - out := os.Stdout - if *outFlag != "-" { - var err error - out, err = os.Create(*outFlag) - if err != nil { - printAndExit("Error opening %q: %s", *outFlag, err) - } - defer out.Close() - } - - var symbols []string - // Only add first instance of any symbol; keep track of them in this map. - added := make(map[string]struct{}) - for _, archive := range archiveFiles { - f, err := os.Open(archive) - if err != nil { - printAndExit("Error opening %s: %s", archive, err) - } - objectFiles, err := ar.ParseAR(f) - f.Close() - if err != nil { - printAndExit("Error parsing %s: %s", archive, err) - } - - for name, contents := range objectFiles { - syms, err := listSymbols(contents) - if err != nil { - printAndExit("Error listing symbols from %q in %q: %s", name, archive, err) - } - for _, s := range syms { - if _, ok := added[s]; !ok { - added[s] = struct{}{} - symbols = append(symbols, s) - } - } - } - } - - sort.Strings(symbols) - for _, s := range symbols { - var skipSymbols = []string{ - // Inline functions, etc., from the compiler or language - // runtime will naturally end up in the library, to be - // deduplicated against other object files. Such symbols - // should not be prefixed. It is a limitation of this - // symbol-prefixing strategy that we cannot distinguish - // our own inline symbols (which should be prefixed) - // from the system's (which should not), so we blacklist - // known system symbols. - "__local_stdio_printf_options", - "__local_stdio_scanf_options", - "_vscprintf", - "_vscprintf_l", - "_vsscanf_l", - "_xmm", - "sscanf", - "vsnprintf", - // sdallocx is a weak symbol and intended to merge with - // the real one, if present. - "sdallocx", - } - var skip bool - for _, sym := range skipSymbols { - if sym == s { - skip = true - break - } - } - if skip || isCXXSymbol(s) || strings.HasPrefix(s, "__real@") || strings.HasPrefix(s, "__x86.get_pc_thunk.") { - continue - } - if _, err := fmt.Fprintln(out, s); err != nil { - printAndExit("Error writing to %s: %s", *outFlag, err) - } - } -} - -func isCXXSymbol(s string) bool { - if *objFileFormat == ObjFileFormatPE { - return strings.HasPrefix(s, "?") - } - return strings.HasPrefix(s, "_Z") -} - -// listSymbols lists the exported symbols from an object file. -func listSymbols(contents []byte) ([]string, error) { - switch *objFileFormat { - case ObjFileFormatELF: - return listSymbolsELF(contents) - case ObjFileFormatMachO: - return listSymbolsMachO(contents) - case ObjFileFormatPE: - return listSymbolsPE(contents) - default: - return nil, fmt.Errorf("unsupported object file format %q", *objFileFormat) - } -} - -func listSymbolsELF(contents []byte) ([]string, error) { - f, err := elf.NewFile(bytes.NewReader(contents)) - if err != nil { - return nil, err - } - syms, err := f.Symbols() - if err != nil { - return nil, err - } - - var names []string - for _, sym := range syms { - // Only include exported, defined symbols - if elf.ST_BIND(sym.Info) != elf.STB_LOCAL && sym.Section != elf.SHN_UNDEF { - names = append(names, sym.Name) - } - } - return names, nil -} - -func listSymbolsMachO(contents []byte) ([]string, error) { - f, err := macho.NewFile(bytes.NewReader(contents)) - if err != nil { - return nil, err - } - if f.Symtab == nil { - return nil, nil - } - var names []string - for _, sym := range f.Symtab.Syms { - // Source: https://opensource.apple.com/source/xnu/xnu-3789.51.2/EXTERNAL_HEADERS/mach-o/nlist.h.auto.html - const ( - N_PEXT uint8 = 0x10 // Private external symbol bit - N_EXT uint8 = 0x01 // External symbol bit, set for external symbols - N_TYPE uint8 = 0x0e // mask for the type bits - - N_UNDF uint8 = 0x0 // undefined, n_sect == NO_SECT - N_ABS uint8 = 0x2 // absolute, n_sect == NO_SECT - N_SECT uint8 = 0xe // defined in section number n_sect - N_PBUD uint8 = 0xc // prebound undefined (defined in a dylib) - N_INDR uint8 = 0xa // indirect - ) - - // Only include exported, defined symbols. - if sym.Type&N_EXT != 0 && sym.Type&N_TYPE != N_UNDF { - if len(sym.Name) == 0 || sym.Name[0] != '_' { - return nil, fmt.Errorf("unexpected symbol without underscore prefix: %q", sym.Name) - } - names = append(names, sym.Name[1:]) - } - } - return names, nil -} - -func listSymbolsPE(contents []byte) ([]string, error) { - f, err := pe.NewFile(bytes.NewReader(contents)) - if err != nil { - return nil, err - } - var ret []string - for _, sym := range f.Symbols { - const ( - // https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format#section-number-values - IMAGE_SYM_UNDEFINED = 0 - // https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format#storage-class - IMAGE_SYM_CLASS_EXTERNAL = 2 - ) - if sym.SectionNumber != IMAGE_SYM_UNDEFINED && sym.StorageClass == IMAGE_SYM_CLASS_EXTERNAL { - name := sym.Name - if f.Machine == pe.IMAGE_FILE_MACHINE_I386 { - // On 32-bit Windows, C symbols are decorated by calling - // convention. - // https://msdn.microsoft.com/en-us/library/56h2zst2.aspx#FormatC - if strings.HasPrefix(name, "_") || strings.HasPrefix(name, "@") { - // __cdecl, __stdcall, or __fastcall. Remove the prefix and - // suffix, if present. - name = name[1:] - if idx := strings.LastIndex(name, "@"); idx >= 0 { - name = name[:idx] - } - } else if idx := strings.LastIndex(name, "@@"); idx >= 0 { - // __vectorcall. Remove the suffix. - name = name[:idx] - } - } - ret = append(ret, name) - } - } - return ret, nil -}