From 2d09ea65bc7b020f5738fd3f48060fff7d58e7c4 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Fri, 24 Jun 2022 15:49:18 +0200 Subject: [PATCH] dwarf/frame: discard indirect flag reading personality func in eh_frame (#3032) We don't do anything with the personality function so there is no point in complaining that we don't fully support the pointer encoding flags used to describe it. This matches the current level of support of pointer encodings in gdb (they are discarded when reading the personality function and not supported for FDEs because gcc doesn't generate them). Fixes #3015 --- pkg/dwarf/frame/entries.go | 10 +++++++--- pkg/dwarf/frame/parser.go | 7 ++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/dwarf/frame/entries.go b/pkg/dwarf/frame/entries.go index 4c6f94d0..1e4605ce 100644 --- a/pkg/dwarf/frame/entries.go +++ b/pkg/dwarf/frame/entries.go @@ -108,8 +108,8 @@ func (fdes FrameDescriptionEntries) Append(otherFDEs FrameDescriptionEntries) Fr // ptrEnc represents a pointer encoding value, used during eh_frame decoding // to determine how pointers were encoded. // Least significant 4 (0xf) bytes encode the size as well as its -// signed-ness, most significant 4 bytes (0xf0) are flags describing how -// the value should be interpreted (absolute, relative...) +// signed-ness, most significant 4 bytes (0xf0 == ptrEncFlagsMask) are flags +// describing how the value should be interpreted (absolute, relative...) // See https://www.airs.com/blog/archives/460. type ptrEnc uint8 @@ -126,12 +126,16 @@ const ( ptrEncSdata4 ptrEnc = 0x0b // 4 bytes, signed ptrEncSdata8 ptrEnc = 0x0c // 8 bytes, signed + ptrEncFlagsMask ptrEnc = 0xf0 + ptrEncPCRel ptrEnc = 0x10 // value is relative to the memory address where it appears ptrEncTextRel ptrEnc = 0x20 // value is relative to the address of the text section ptrEncDataRel ptrEnc = 0x30 // value is relative to the address of the data section ptrEncFuncRel ptrEnc = 0x40 // value is relative to the start of the function ptrEncAligned ptrEnc = 0x50 // value should be aligned ptrEncIndirect ptrEnc = 0x80 // value is an address where the real value of the pointer is stored + + ptrEncSupportedFlags = ptrEncPCRel ) // Supported returns true if this pointer encoding is supported. @@ -142,7 +146,7 @@ func (ptrEnc ptrEnc) Supported() bool { // These values aren't defined at the moment return false } - if ptrEnc&0xf0 != ptrEncPCRel { + if (ptrEnc&ptrEncFlagsMask)&^ptrEncSupportedFlags != 0 { // Currently only the PC relative flag is supported return false } diff --git a/pkg/dwarf/frame/parser.go b/pkg/dwarf/frame/parser.go index bcec7e56..147ca34f 100644 --- a/pkg/dwarf/frame/parser.go +++ b/pkg/dwarf/frame/parser.go @@ -201,12 +201,13 @@ func parseCIE(ctx *parseContext) parsefunc { // the pointer to the personality function encoded as specified by the // pointer encoding. // We don't support this but have to read it anyway. - e, _ := buf.ReadByte() - if !ptrEnc(e).Supported() { + b, _ := buf.ReadByte() + e := ptrEnc(b) &^ ptrEncIndirect + if !e.Supported() { ctx.err = fmt.Errorf("pointer encoding not supported %#x at %#x", e, ctx.offset()) return nil } - ctx.readEncodedPtr(0, buf, ptrEnc(e)) + ctx.readEncodedPtr(0, buf, e) default: ctx.err = fmt.Errorf("unsupported augmentation character %c at %#x", ctx.common.Augmentation[i], ctx.offset()) return nil