diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2024-01-03 18:04:11 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2024-04-19 21:24:24 +0000 | 
| commit | 0c85e2760f6b5016c16d29f8c2f63f3ba2cf5298 (patch) | |
| tree | d6c9033fa7ca2f632ddc81d371ef3faf921652db /contrib/llvm-project/llvm/lib/Object | |
| parent | 92d4d6f1f60e5d9cb2c7e0dd5d632987e54741e8 (diff) | |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Object')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/Object/WasmObjectFile.cpp | 21 | 
1 files changed, 17 insertions, 4 deletions
| diff --git a/contrib/llvm-project/llvm/lib/Object/WasmObjectFile.cpp b/contrib/llvm-project/llvm/lib/Object/WasmObjectFile.cpp index dfe86a45df32..ccc29d0cb73d 100644 --- a/contrib/llvm-project/llvm/lib/Object/WasmObjectFile.cpp +++ b/contrib/llvm-project/llvm/lib/Object/WasmObjectFile.cpp @@ -1484,6 +1484,11 @@ Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) {      }      uint32_t BodySize = FunctionEnd - Ctx.Ptr; +    // Ensure that Function is within Ctx's buffer. +    if (Ctx.Ptr + BodySize > Ctx.End) { +      return make_error<GenericBinaryError>("Function extends beyond buffer", +                                            object_error::parse_failed); +    }      Function.Body = ArrayRef<uint8_t>(Ctx.Ptr, BodySize);      // This will be set later when reading in the linking metadata section.      Function.Comdat = UINT32_MAX; @@ -1662,10 +1667,18 @@ Expected<StringRef> WasmObjectFile::getSymbolName(DataRefImpl Symb) const {  Expected<uint64_t> WasmObjectFile::getSymbolAddress(DataRefImpl Symb) const {    auto &Sym = getWasmSymbol(Symb);    if (Sym.Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION && -      isDefinedFunctionIndex(Sym.Info.ElementIndex)) -    return getDefinedFunction(Sym.Info.ElementIndex).CodeSectionOffset; -  else -    return getSymbolValue(Symb); +      isDefinedFunctionIndex(Sym.Info.ElementIndex)) { +    // For object files, use the section offset. The linker relies on this. +    // For linked files, use the file offset. This behavior matches the way +    // browsers print stack traces and is useful for binary size analysis. +    // (see https://webassembly.github.io/spec/web-api/index.html#conventions) +    uint32_t Adjustment = isRelocatableObject() || isSharedObject() +                              ? 0 +                              : Sections[CodeSection].Offset; +    return getDefinedFunction(Sym.Info.ElementIndex).CodeSectionOffset + +           Adjustment; +  } +  return getSymbolValue(Symb);  }  uint64_t WasmObjectFile::getWasmSymbolValue(const WasmSymbol &Sym) const { | 
