[llvm] r329820 - [DWARFv5] Fuss with asm syntax for conveying MD5 checksum.

Paul Robinson via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 11 08:14:05 PDT 2018


Author: probinson
Date: Wed Apr 11 08:14:05 2018
New Revision: 329820

URL: http://llvm.org/viewvc/llvm-project?rev=329820&view=rev
Log:
[DWARFv5] Fuss with asm syntax for conveying MD5 checksum.

Previously the MD5 option of the .file directive provided the checksum
as a quoted hex string; now it's a normal hex number with 0x prefix,
same as the .octa directive accepts.

Differential Revision: https://reviews.llvm.org/D45459

Modified:
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll
    llvm/trunk/test/MC/ELF/debug-file-options.s
    llvm/trunk/test/MC/ELF/debug-md5-err.s
    llvm/trunk/test/MC/ELF/debug-md5.s

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=329820&r1=329819&r2=329820&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Wed Apr 11 08:14:05 2018
@@ -1106,10 +1106,8 @@ static void printDwarfFileDirective(unsi
     OS << ' ';
   }
   PrintQuotedString(Filename, OS);
-  if (Checksum) {
-    OS << " md5 ";
-    PrintQuotedString(Checksum->digest(), OS);
-  }
+  if (Checksum)
+    OS << " md5 0x" << Checksum->digest();
   if (Source) {
     OS << " source ";
     PrintQuotedString(*Source, OS);

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=329820&r1=329819&r2=329820&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Wed Apr 11 08:14:05 2018
@@ -2969,6 +2969,25 @@ bool AsmParser::parseDirectiveValue(Stri
   return false;
 }
 
+static bool parseHexOcta(AsmParser &Asm, uint64_t &hi, uint64_t &lo) {
+  if (Asm.getTok().isNot(AsmToken::Integer) &&
+      Asm.getTok().isNot(AsmToken::BigNum))
+    return Asm.TokError("unknown token in expression");
+  SMLoc ExprLoc = Asm.getTok().getLoc();
+  APInt IntValue = Asm.getTok().getAPIntVal();
+  Asm.Lex();
+  if (!IntValue.isIntN(128))
+    return Asm.Error(ExprLoc, "out of range literal value");
+  if (!IntValue.isIntN(64)) {
+    hi = IntValue.getHiBits(IntValue.getBitWidth() - 64).getZExtValue();
+    lo = IntValue.getLoBits(64).getZExtValue();
+  } else {
+    hi = 0;
+    lo = IntValue.getZExtValue();
+  }
+  return false;
+}
+
 /// ParseDirectiveOctaValue
 ///  ::= .octa [ hexconstant (, hexconstant)* ]
 
@@ -2976,21 +2995,9 @@ bool AsmParser::parseDirectiveOctaValue(
   auto parseOp = [&]() -> bool {
     if (checkForValidSection())
       return true;
-    if (getTok().isNot(AsmToken::Integer) && getTok().isNot(AsmToken::BigNum))
-      return TokError("unknown token in expression");
-    SMLoc ExprLoc = getTok().getLoc();
-    APInt IntValue = getTok().getAPIntVal();
     uint64_t hi, lo;
-    Lex();
-    if (!IntValue.isIntN(128))
-      return Error(ExprLoc, "out of range literal value");
-    if (!IntValue.isIntN(64)) {
-      hi = IntValue.getHiBits(IntValue.getBitWidth() - 64).getZExtValue();
-      lo = IntValue.getLoBits(64).getZExtValue();
-    } else {
-      hi = 0;
-      lo = IntValue.getZExtValue();
-    }
+    if (parseHexOcta(*this, hi, lo))
+      return true;
     if (MAI.isLittleEndian()) {
       getStreamer().EmitIntValue(lo, 8);
       getStreamer().EmitIntValue(hi, 8);
@@ -3283,7 +3290,8 @@ bool AsmParser::parseDirectiveFile(SMLoc
     Filename = Path;
   }
 
-  std::string Checksum;
+  uint64_t MD5Hi, MD5Lo;
+  bool HasMD5 = false;
 
   Optional<StringRef> Source;
   bool HasSource = false;
@@ -3296,12 +3304,10 @@ bool AsmParser::parseDirectiveFile(SMLoc
         parseIdentifier(Keyword))
       return true;
     if (Keyword == "md5") {
+      HasMD5 = true;
       if (check(FileNumber == -1,
                 "MD5 checksum specified, but no file number") ||
-          check(getTok().isNot(AsmToken::String),
-                "unexpected token in '.file' directive") ||
-          parseEscapedString(Checksum) ||
-          check(Checksum.size() != 32, "invalid MD5 checksum specified"))
+          parseHexOcta(*this, MD5Hi, MD5Lo))
         return true;
     } else if (Keyword == "source") {
       HasSource = true;
@@ -3324,12 +3330,12 @@ bool AsmParser::parseDirectiveFile(SMLoc
     getStreamer().EmitFileDirective(Filename);
   else {
     MD5::MD5Result *CKMem = nullptr;
-    if (!Checksum.empty()) {
-      Checksum = fromHex(Checksum);
-      if (check(Checksum.size() != 16, "invalid MD5 checksum specified"))
-        return true;
+    if (HasMD5) {
       CKMem = (MD5::MD5Result *)Ctx.allocate(sizeof(MD5::MD5Result), 1);
-      memcpy(&CKMem->Bytes, Checksum.data(), 16);
+      for (unsigned i = 0; i != 8; ++i) {
+        CKMem->Bytes[i] = uint8_t(MD5Hi >> ((7 - i) * 8));
+        CKMem->Bytes[i + 8] = uint8_t(MD5Lo >> ((7 - i) * 8));
+      }
     }
     if (HasSource) {
       char *SourceBuf = static_cast<char *>(Ctx.allocate(SourceString.size()));

Modified: llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll?rev=329820&r1=329819&r2=329820&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll (original)
+++ llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll Wed Apr 11 08:14:05 2018
@@ -13,13 +13,13 @@
 ; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefixes=OBJ,OBJ-5
 
 ; ASM-4-NOT: .file 0
-; ASM-5: .file 0 "/scratch{{.*[/\\]}}t.c" md5 "00000000000000000000000000000000"
+; ASM-5: .file 0 "/scratch{{.*[/\\]}}t.c" md5 0x00000000000000000000000000000000
 ; ASM: .file 1 "/scratch{{.*[/\\]}}t1.h"
 ; ASM-4-NOT:  md5
-; ASM-5-SAME: md5 "11111111111111111111111111111111"
+; ASM-5-SAME: md5 0x11111111111111111111111111111111
 ; ASM: .file 2 "/scratch{{.*[/\\]}}t2.h"
 ; ASM-4-NOT:  md5
-; ASM-5-SAME: md5 "22222222222222222222222222222222"
+; ASM-5-SAME: md5 0x22222222222222222222222222222222
 
 ; OBJ-5: file_names[ 0]:
 ; OBJ-5-NEXT: name: "t.c"

Modified: llvm/trunk/test/MC/ELF/debug-file-options.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-file-options.s?rev=329820&r1=329819&r2=329820&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/debug-file-options.s (original)
+++ llvm/trunk/test/MC/ELF/debug-file-options.s Wed Apr 11 08:14:05 2018
@@ -2,8 +2,8 @@
 
 // Test combinations of options to the .file directive.
 
-        .file 1 "dir1/foo" md5 "ee87e05688663173cd6043a3a15bba6e" source "void foo() {}"
-        .file 2 "dir2/bar" source "void bar() {}" md5 "816225a0c90ca8948b70eb58be4d522f"
+        .file 1 "dir1/foo" md5 0xee87e05688663173cd6043a3a15bba6e source "void foo() {}"
+        .file 2 "dir2/bar" source "void bar() {}" md5 0x816225a0c90ca8948b70eb58be4d522f
         .loc 1 1 0
         nop
         .loc 2 1 0

Modified: llvm/trunk/test/MC/ELF/debug-md5-err.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-md5-err.s?rev=329820&r1=329819&r2=329820&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/debug-md5-err.s (original)
+++ llvm/trunk/test/MC/ELF/debug-md5-err.s Wed Apr 11 08:14:05 2018
@@ -7,20 +7,20 @@
 
 # Missing md5 keyword.
 # CHECK: [[@LINE+1]]:{{[0-9]+}}: error: unexpected token in '.file' directive
-        .file 2 "dir1" "foo" "00112233445566778899aabbccddeeff"
+        .file 2 "dir1" "foo" 0x00112233445566778899aabbccddeeff
 
-# Bad length.
-# CHECK: [[@LINE+1]]:{{[0-9]+}}: error: invalid MD5 checksum specified
+# Bad syntax.
+# CHECK: [[@LINE+1]]:{{[0-9]+}}: error: unknown token in expression
         .file 3 "dir2" "bar" md5 "ff"
 
-# Not a string.
-# CHECK: [[@LINE+1]]:{{[0-9]+}}: error: unexpected token in '.file' directive
+# No hex prefix.
+# CHECK: [[@LINE+1]]:{{[0-9]+}}: error: unknown token in expression
         .file 4 "dir3" "foo" md5 ffeeddccbbaa99887766554433221100
 
 # Non-DWARF .file syntax with checksum.
 # CHECK: [[@LINE+1]]:{{[0-9]+}}: error: MD5 checksum specified, but no file number
-        .file "baz" md5 "ffeeddccbbaa998877665544332211gg"
+        .file "baz" md5 0xffeeddccbbaa99887766554433221100
 
 # Inconsistent use of MD5 option. Note: .file 1 did not supply one.
 # CHECK: [[@LINE+1]]:{{[0-9]+}}: error: inconsistent use of MD5 checksums
-        .file 5 "bax" md5 "ffeeddccbbaa99887766554433221100"
+        .file 5 "bax" md5 0xffeeddccbbaa99887766554433221100

Modified: llvm/trunk/test/MC/ELF/debug-md5.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-md5.s?rev=329820&r1=329819&r2=329820&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/debug-md5.s (original)
+++ llvm/trunk/test/MC/ELF/debug-md5.s Wed Apr 11 08:14:05 2018
@@ -1,7 +1,7 @@
 // RUN: llvm-mc -triple x86_64-unknown-unknown -dwarf-version 5 -fdebug-compilation-dir=/tmp -filetype=obj %s -o - | llvm-dwarfdump --debug-line --debug-line-str -v - | FileCheck %s
 
-        .file 1 "dir1/foo"   md5 "00112233445566778899aabbccddeeff"
-        .file 2 "dir2" "bar" md5 "ffeeddccbbaa99887766554433221100"
+        .file 1 "dir1/foo"   md5 0x00112233445566778899aabbccddeeff
+        .file 2 "dir2" "bar" md5 0xffeeddccbbaa99887766554433221100
         .loc 1 1 0
         nop
         .loc 2 1 0




More information about the llvm-commits mailing list