Skip to content

Commit d4430f6

Browse files
dagoodqmuntal
authored andcommitted
cmd/link/internal/loadpe: fix .xdata unwind info parsing
Unwind info in .xdata was being parsed incorrectly, causing targetOff to be incorrect and miss finding data in .xdata that it should have found. This causes a linker issue when using the MinGW MSVCRT compiler. Contains several fixes based on the exception handling docs: the offset used to get the number of unwind codes, the calculation of the target offset based on the dynamic size of the unwind data, and the UNW_FLAG_CHAININFO flag's value. Fixes #64200 Change-Id: I6483d921b2bf8a2512a95223bf3c8ce8bc63dc4a Reviewed-on: https://go-review.googlesource.com/c/go/+/544415 TryBot-Result: Gopher Robot <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Quim Muntal <[email protected]> Run-TryBot: Quim Muntal <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent 37971b3 commit d4430f6

File tree

1 file changed

+5
-4
lines changed
  • src/cmd/link/internal/loadpe

1 file changed

+5
-4
lines changed

src/cmd/link/internal/loadpe/seh.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
const (
1717
UNW_FLAG_EHANDLER = 1 << 3
1818
UNW_FLAG_UHANDLER = 2 << 3
19-
UNW_FLAG_CHAININFO = 3 << 3
20-
unwStaticDataSize = 8
19+
UNW_FLAG_CHAININFO = 4 << 3
20+
unwStaticDataSize = 4 // Bytes of unwind data before the variable length part.
21+
unwCodeSize = 2 // Bytes per unwind code.
2122
)
2223

2324
// processSEH walks all pdata relocations looking for exception handler function symbols.
@@ -81,14 +82,14 @@ func findHandlerInXDataAMD64(ldr *loader.Loader, xsym sym.LoaderSym, add int64)
8182
// Nothing to do.
8283
return 0
8384
}
84-
codes := data[3]
85+
codes := data[2]
8586
if codes%2 != 0 {
8687
// There are always an even number of unwind codes, even if the last one is unused.
8788
codes += 1
8889
}
8990
// The exception handler relocation is the first relocation after the unwind codes,
9091
// unless it is chained, but we will handle this case later.
91-
targetOff := add + unwStaticDataSize*(1+int64(codes))
92+
targetOff := add + unwStaticDataSize + unwCodeSize*int64(codes)
9293
xrels := ldr.Relocs(xsym)
9394
xrelsCount := xrels.Count()
9495
idx := sort.Search(xrelsCount, func(i int) bool {

0 commit comments

Comments
 (0)