[PATCH] D70062: MCObjectStreamer: assign MCSymbols in the dummy fragment to offset 0.

James Y Knight via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 10 13:35:21 PST 2019


jyknight created this revision.
jyknight added reviewers: MaskRay, jcai19, nickdesaulniers, peter.smith.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

In MCObjectStreamer, when there is no current fragment, initially
symbols are created in a "pending" state and assigned to a dummy
empty fragment.

Previously, they were not being assigned an offset, and thus
evaluateAbsolute would fail if trying to evaluate an expression 'a -
b', where both 'a' and 'b' were in this pending state.

Fixes: https://llvm.org/PR41825


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70062

Files:
  llvm/lib/MC/MCObjectStreamer.cpp
  llvm/test/MC/AsmParser/assembler-expressions.s


Index: llvm/test/MC/AsmParser/assembler-expressions.s
===================================================================
--- llvm/test/MC/AsmParser/assembler-expressions.s
+++ llvm/test/MC/AsmParser/assembler-expressions.s
@@ -5,7 +5,7 @@
 
 # OBJDATA: Contents of section .data
 # OBJDATA-NEXT: 0000 aa0506ff
-	
+
 foo2:
 # ASM-ERR: [[@LINE+1]]:5: error: expected absolute expression
 .if . - foo2 == 0
@@ -26,17 +26,22 @@
 .byte 0xff
 
 # nop is a fixed size instruction so this should pass.
-	
+
 # OBJTEXT: Contents of section .text
-# OBJTEXT-NEXT: 0000 9090ff34 25000000 00909090 78563412
-# OBJTEXT-NEXT: 0010 78563412 90
+# OBJTEXT-NEXT: 0000 909090ff 34250000 00009090 90785634
+# OBJTEXT-NEXT: 0010 12785634 1290
 
 .text
-	
 text1:
+# ASM-ERR: [[@LINE+1]]:5: error: expected absolute expression
+.if . - text1 == 0
+	nop
+.endif
+
+text2:
         nop
 # ASM-ERR: [[@LINE+1]]:5: error: expected absolute expression
-.if . - text1 == 1
+.if . - text2 == 1
 	nop
 .else
 	ret
@@ -46,15 +51,14 @@
 	nop
 	nop
 # No additional errors.
-#	
+#
 # ASM-ERR-NOT: {{[0-9]+}}:{{[0-9]+}}: error:
 
-	
 
-text2:
-	.long 0x12345678
 text3:
-	.fill (text3-text2)/4, 4, 0x12345678
+	.long 0x12345678
+text4:
+	.fill (text4-text3)/4, 4, 0x12345678
 	nop
 
 
Index: llvm/lib/MC/MCObjectStreamer.cpp
===================================================================
--- llvm/lib/MC/MCObjectStreamer.cpp
+++ llvm/lib/MC/MCObjectStreamer.cpp
@@ -243,6 +243,10 @@
     Symbol->setFragment(F);
     Symbol->setOffset(F->getContents().size());
   } else {
+    // Assign all pending labels to offset 0 within the dummy "pending"
+    // fragment. (They will all be reassigned to a real fragment in
+    // flushPendingLabels())
+    Symbol->setOffset(0);
     PendingLabels.push_back(Symbol);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70062.228625.patch
Type: text/x-patch
Size: 1791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191110/edd66fdb/attachment-0001.bin>


More information about the llvm-commits mailing list