[PATCH] D45773: [RISCV] Don't fold symbol diff

Edward Jones via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 18 08:41:17 PDT 2018


edward-jones created this revision.
edward-jones added reviewers: simoncook, asb.
Herald added subscribers: llvm-commits, shiva0217, kito-cheng, JDevlieghere, aprantl.

When emitting the difference between two symbols, the standard behavior is that the difference will be resolved to an absolute value if both of the symbols are offsets from the same data fragment. This is undesirable on architectures such as RISC-V where relaxation in the linker may cause the computed difference to become invalid. This caused an issue when compiling to object code, where the size of a function in the debug information was already calculated even though it could change as a consequence of relaxation in the subsequent linking stage.

This patch inhibits the resolution of symbol differences to absolute values where the target's AsmBackend has declared that it does not want these to be folded.


Repository:
  rL LLVM

https://reviews.llvm.org/D45773

Files:
  include/llvm/MC/MCObjectStreamer.h
  lib/MC/MCObjectStreamer.cpp


Index: lib/MC/MCObjectStreamer.cpp
===================================================================
--- lib/MC/MCObjectStreamer.cpp
+++ lib/MC/MCObjectStreamer.cpp
@@ -53,9 +53,12 @@
 
 // As a compile-time optimization, avoid allocating and evaluating an MCExpr
 // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
-static Optional<uint64_t> absoluteSymbolDiff(const MCSymbol *Hi,
-                                             const MCSymbol *Lo) {
+Optional<uint64_t>
+MCObjectStreamer::absoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo) {
   assert(Hi && Lo);
+  if (TAB->requiresDiffExpressionRelocations())
+    return None;
+
   if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
       Hi->isVariable() || Lo->isVariable())
     return None;
Index: include/llvm/MC/MCObjectStreamer.h
===================================================================
--- include/llvm/MC/MCObjectStreamer.h
+++ include/llvm/MC/MCObjectStreamer.h
@@ -169,11 +169,18 @@
 
   void FinishImpl() override;
 
+private:
+  Optional<uint64_t> absoluteSymbolDiff(const MCSymbol *hi,
+                                        const MCSymbol *Lo);
+
+public:
   /// Emit the absolute difference between two symbols if possible.
   ///
   /// Emit the absolute difference between \c Hi and \c Lo, as long as we can
   /// compute it.  Currently, that requires that both symbols are in the same
-  /// data fragment.  Otherwise, do nothing and return \c false.
+  /// data fragment and that the target has not specified that diff expressions
+  /// require relocations to be emitted. Otherwise, do nothing and return
+  /// \c false.
   ///
   /// \pre Offset of \c Hi is greater than the offset \c Lo.
   void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45773.142944.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180418/6b8f05e1/attachment.bin>


More information about the llvm-commits mailing list