[PATCH] D28878: Fix aliases to thumbfunc-based exprs to be thumbfunc

Evgeniy Stepanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 15:59:20 PST 2017


eugenis created this revision.
Herald added a subscriber: rengolin.

If F is a Thumb function symbol, and G = F + const, and G is a
function symbol, then G is Thumb. Because what else could it be?

This is how ControlFlowIntegrity emits jump tables - a function with inline asm that's a bunch of jump instructions, and a set of aliases inside that function. If a function is thumb, we want the aliases to be thumb as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D28878

Files:
  lib/MC/MCAssembler.cpp
  test/MC/ARM/elf-thumbfunc.s


Index: test/MC/ARM/elf-thumbfunc.s
===================================================================
--- test/MC/ARM/elf-thumbfunc.s
+++ test/MC/ARM/elf-thumbfunc.s
@@ -14,6 +14,9 @@
 	.global bar
 bar = foo
 
+	.global baz
+baz = foo + 2
+
 @@ make sure foo and bar are thumb function: bit 0 = 1 (st_value)
 @CHECK:        Symbol {
 @CHECK:          Name: bar
@@ -23,6 +26,13 @@
 @CHECK-NEXT:     Type: Function
 
 @CHECK:        Symbol {
+ at CHECK:          Name: baz
+ at CHECK-NEXT:     Value: 0x3
+ at CHECK-NEXT:     Size: 0
+ at CHECK-NEXT:     Binding: Global
+ at CHECK-NEXT:     Type: Function
+
+ at CHECK:        Symbol {
 @CHECK:          Name: foo
 @CHECK-NEXT:     Value: 0x1
 @CHECK-NEXT:     Size: 0
Index: lib/MC/MCAssembler.cpp
===================================================================
--- lib/MC/MCAssembler.cpp
+++ lib/MC/MCAssembler.cpp
@@ -114,10 +114,16 @@
   if (!Symbol->isVariable())
     return false;
 
-  // FIXME: It looks like gas supports some cases of the form "foo + 2". It
-  // is not clear if that is a bug or a feature.
   const MCExpr *Expr = Symbol->getVariableValue();
-  const MCSymbolRefExpr *Ref = dyn_cast<MCSymbolRefExpr>(Expr);
+
+  MCValue V;
+  if (!Expr->evaluateAsRelocatable(V, nullptr, nullptr))
+    return false;
+
+  if (V.getSymB() || V.getRefKind() != MCSymbolRefExpr::VK_None)
+    return false;
+
+  const MCSymbolRefExpr *Ref = V.getSymA();
   if (!Ref)
     return false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28878.84901.patch
Type: text/x-patch
Size: 1432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170118/0250e765/attachment.bin>


More information about the llvm-commits mailing list