[PATCH] D12610: [dsymutil] Ensure PC offsets with within specified bit width
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 3 15:00:30 PDT 2015
vsk created this revision.
vsk added a reviewer: friss.
vsk added a subscriber: llvm-commits.
Fixes a bug where dsymutil did not truncate negative PC offsets to the specified width. E.g: if "Low + LocPcOffset" is negative and AddressSize is 4, the bits 32..63 are high, which causes EmitIntValue to assertion-fail.
http://reviews.llvm.org/D12610
Files:
include/llvm/Support/MathExtras.h
tools/dsymutil/DwarfLinker.cpp
Index: tools/dsymutil/DwarfLinker.cpp
===================================================================
--- tools/dsymutil/DwarfLinker.cpp
+++ tools/dsymutil/DwarfLinker.cpp
@@ -34,6 +34,7 @@
#include "llvm/Object/MachO.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/LEB128.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
@@ -838,8 +839,10 @@
Asm->OutStreamer->EmitIntValue(0, AddressSize);
break;
}
- Asm->OutStreamer->EmitIntValue(Low + LocPcOffset, AddressSize);
- Asm->OutStreamer->EmitIntValue(High + LocPcOffset, AddressSize);
+ Asm->OutStreamer->EmitIntValue(
+ llvm::Lo_Bits(Low + LocPcOffset, 8 * AddressSize), AddressSize);
+ Asm->OutStreamer->EmitIntValue(
+ llvm::Lo_Bits(High + LocPcOffset, 8 * AddressSize), AddressSize);
uint64_t Length = Data.getU16(&Offset);
Asm->OutStreamer->EmitIntValue(Length, 2);
// Just copy the bytes over.
Index: include/llvm/Support/MathExtras.h
===================================================================
--- include/llvm/Support/MathExtras.h
+++ include/llvm/Support/MathExtras.h
@@ -252,6 +252,12 @@
return static_cast<uint32_t>(Value);
}
+/// Lo_Bits - This function returns the low \p Bits bits of Value.
+inline uint64_t Lo_Bits(uint64_t Value, unsigned Bits) {
+ assert(Bits <= 64);
+ return Value & (~0ULL >> (64 - Bits));
+}
+
/// Make_64 - This functions makes a 64-bit integer from a high / low pair of
/// 32-bit integers.
inline uint64_t Make_64(uint32_t High, uint32_t Low) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12610.33979.patch
Type: text/x-patch
Size: 1677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150903/f0316eab/attachment.bin>
More information about the llvm-commits
mailing list