diff options
| author | Paul Robinson <paul.robinson@sony.com> | 2018-04-11 15:14:05 +0000 |
|---|---|---|
| committer | Paul Robinson <paul.robinson@sony.com> | 2018-04-11 15:14:05 +0000 |
| commit | 0195469a238095c451ce00008d94abd53a055451 (patch) | |
| tree | 79a9d25d37ebb3a780af31fd9cebef5b4711c3f9 | |
| parent | 366857a23ab44247d5c8651bb067920b0306626b (diff) | |
| download | bcm5719-llvm-0195469a238095c451ce00008d94abd53a055451.tar.gz bcm5719-llvm-0195469a238095c451ce00008d94abd53a055451.zip | |
[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
llvm-svn: 329820
| -rw-r--r-- | llvm/lib/MC/MCAsmStreamer.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/MC/MCParser/AsmParser.cpp | 54 | ||||
| -rw-r--r-- | llvm/test/CodeGen/Generic/dwarf-md5.ll | 6 | ||||
| -rw-r--r-- | llvm/test/MC/ELF/debug-file-options.s | 4 | ||||
| -rw-r--r-- | llvm/test/MC/ELF/debug-md5-err.s | 14 | ||||
| -rw-r--r-- | llvm/test/MC/ELF/debug-md5.s | 4 |
6 files changed, 46 insertions, 42 deletions
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 01e1744b134..47da067f493 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -1106,10 +1106,8 @@ static void printDwarfFileDirective(unsigned FileNo, StringRef Directory, 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); diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 08f5bb2cd2c..69720135432 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -2969,6 +2969,25 @@ bool AsmParser::parseDirectiveValue(StringRef IDVal, unsigned Size) { 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(StringRef IDVal) { 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 DirectiveLoc) { 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 DirectiveLoc) { 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 DirectiveLoc) { 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())); diff --git a/llvm/test/CodeGen/Generic/dwarf-md5.ll b/llvm/test/CodeGen/Generic/dwarf-md5.ll index 745f433facb..dc2d92c10d4 100644 --- a/llvm/test/CodeGen/Generic/dwarf-md5.ll +++ b/llvm/test/CodeGen/Generic/dwarf-md5.ll @@ -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" diff --git a/llvm/test/MC/ELF/debug-file-options.s b/llvm/test/MC/ELF/debug-file-options.s index 5c77a48ab72..dd1bdcf71f0 100644 --- a/llvm/test/MC/ELF/debug-file-options.s +++ b/llvm/test/MC/ELF/debug-file-options.s @@ -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 diff --git a/llvm/test/MC/ELF/debug-md5-err.s b/llvm/test/MC/ELF/debug-md5-err.s index fef628df80a..376e5fa1973 100644 --- a/llvm/test/MC/ELF/debug-md5-err.s +++ b/llvm/test/MC/ELF/debug-md5-err.s @@ -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 diff --git a/llvm/test/MC/ELF/debug-md5.s b/llvm/test/MC/ELF/debug-md5.s index 658e02e5917..a9aaa2b961a 100644 --- a/llvm/test/MC/ELF/debug-md5.s +++ b/llvm/test/MC/ELF/debug-md5.s @@ -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 |

