]> Cypherpunks repositories - gostls13.git/commitdiff
debug/pe: handle files with no string table
authorAlex Brainman <alex.brainman@gmail.com>
Fri, 17 Jun 2016 04:05:35 +0000 (14:05 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Sun, 19 Jun 2016 05:18:09 +0000 (05:18 +0000)
pecoff.doc (https://goo.gl/ayvckk) in section 5.6 says:

Immediately following the COFF symbol table is the COFF string table.
The position of this table is found by taking the symbol table address
in the COFF header, and adding the number of symbols multiplied by
the size of a symbol.

So it is unclear what to do when symbol table address is 0.
Lets assume executable does not have any string table.

Added new test with executable with no symbol table. The

gcc -s testdata\hello.c -o testdata\gcc-386-mingw-no-symbols-exec.

command was used to generate the executable.

Fixes #16084

Change-Id: Ie74137ac64b15daadd28e1f0315f3b62d1bf2059
Reviewed-on: https://go-review.googlesource.com/24200
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/debug/pe/file_test.go
src/debug/pe/string.go
src/debug/pe/testdata/gcc-386-mingw-no-symbols-exec [new file with mode: 0644]

index 12059b5effeb299a214ee989c1aa560ec5dc2d80..964caf56ec7479022be91adaa74c6102aa8ffd0f 100644 (file)
@@ -104,6 +104,41 @@ var fileTests = []fileTest{
                        {".debug_loc", 0x38, 0xf000, 0x200, 0x3a00, 0x0, 0x0, 0x0, 0x0, 0x42100000},
                },
        },
+       {
+               file: "testdata/gcc-386-mingw-no-symbols-exec",
+               hdr:  FileHeader{0x14c, 0x8, 0x69676572, 0x0, 0x0, 0xe0, 0x30f},
+               opthdr: &OptionalHeader32{0x10b, 0x2, 0x18, 0xe00, 0x1e00, 0x200, 0x1280, 0x1000, 0x2000, 0x400000, 0x1000, 0x200, 0x4, 0x0, 0x1, 0x0, 0x4, 0x0, 0x0, 0x9000, 0x400, 0x5306, 0x3, 0x0, 0x200000, 0x1000, 0x100000, 0x1000, 0x0, 0x10,
+                       [16]DataDirectory{
+                               {0x0, 0x0},
+                               {0x6000, 0x378},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                               {0x8004, 0x18},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                               {0x60b8, 0x7c},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                               {0x0, 0x0},
+                       },
+               },
+               sections: []*SectionHeader{
+                       {".text", 0xc64, 0x1000, 0xe00, 0x400, 0x0, 0x0, 0x0, 0x0, 0x60500060},
+                       {".data", 0x10, 0x2000, 0x200, 0x1200, 0x0, 0x0, 0x0, 0x0, 0xc0300040},
+                       {".rdata", 0x134, 0x3000, 0x200, 0x1400, 0x0, 0x0, 0x0, 0x0, 0x40300040},
+                       {".eh_fram", 0x3a0, 0x4000, 0x400, 0x1600, 0x0, 0x0, 0x0, 0x0, 0x40300040},
+                       {".bss", 0x60, 0x5000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0300080},
+                       {".idata", 0x378, 0x6000, 0x400, 0x1a00, 0x0, 0x0, 0x0, 0x0, 0xc0300040},
+                       {".CRT", 0x18, 0x7000, 0x200, 0x1e00, 0x0, 0x0, 0x0, 0x0, 0xc0300040},
+                       {".tls", 0x20, 0x8000, 0x200, 0x2000, 0x0, 0x0, 0x0, 0x0, 0xc0300040},
+               },
+               hasNoDwarfInfo: true,
+       },
        {
                file: "testdata/gcc-amd64-mingw-obj",
                hdr:  FileHeader{0x8664, 0x6, 0x0, 0x198, 0x12, 0x0, 0x4},
index f5cd130b531298b3dc65c4dce90321dd59a6c755..69837f6d0194eae8b568512bac73e4d95fad4385 100644 (file)
@@ -24,6 +24,9 @@ type _StringTable []byte
 
 func readStringTable(fh *FileHeader, r io.ReadSeeker) (_StringTable, error) {
        // COFF string table is located right after COFF symbol table.
+       if fh.PointerToSymbolTable <= 0 {
+               return nil, nil
+       }
        offset := fh.PointerToSymbolTable + COFFSymbolSize*fh.NumberOfSymbols
        _, err := r.Seek(int64(offset), io.SeekStart)
        if err != nil {
diff --git a/src/debug/pe/testdata/gcc-386-mingw-no-symbols-exec b/src/debug/pe/testdata/gcc-386-mingw-no-symbols-exec
new file mode 100644 (file)
index 0000000..329dca6
Binary files /dev/null and b/src/debug/pe/testdata/gcc-386-mingw-no-symbols-exec differ