-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug information incorrect #222
Comments
Good catch. I'm reluctant to revert these changes wholesale, as LLVM 13+ simply won't work without them. (Printing Do you have a sense for what is causing there to be duplicate |
I haven't had time to track it down. My hunch is that there are two parallel tables or lists somewhere and this drops the entries from one but the output is perhaps iterating over the other, causing issues when there is no correlation. That's a complete guess though. I have so far only used this reverted form with pre-built bitcode from LLVM 12 or earlier; I have not tried it on LLVM 13 or later so hadn't yet discovered that it was broken. I'm fine with using this branch for the moment without merging, since my target is still in the progress of supporting later LLVM versions. I have a couple of other tasks to take care of before I can come back and track this down though, so I'll coordinate with you in case you get to it first. |
Indeed, filtering out entries in !5 = !{}
!7 = !DIGlobalVariableExpression(var: !2, expr: !6)
!8 = !{!7} I suspect that the filtering will need to occur at the point when the unnamed metadata entries are first added to the map that |
I believe part of the issue is in how we register llvm-pretty-bc-parser/src/Data/LLVM/BitCode/IR/Metadata.hs Lines 998 to 1001 in 491840b
Where There are other ways to add metadata to the table without adding them to llvm-pretty-bc-parser/src/Data/LLVM/BitCode/IR/Metadata.hs Lines 85 to 91 in 491840b
Unlike |
diff --git a/src/Data/LLVM/BitCode/IR/Metadata.hs b/src/Data/LLVM/BitCode/IR/Metadata.hs
index b3b4bf2..02eace3 100644
--- a/src/Data/LLVM/BitCode/IR/Metadata.hs
+++ b/src/Data/LLVM/BitCode/IR/Metadata.hs
@@ -90,6 +90,13 @@ addMdValue tv mt = mt { mtEntries = addValue tv' (mtEntries mt) }
, typedValue = ValMd (ValMdValue tv)
}
+addMdDebugInfo :: DebugInfo' Int -> MetadataTable -> MetadataTable
+addMdDebugInfo di mt = mt { mtEntries = addValue tv (mtEntries mt) }
+ where
+ tv = Typed { typedType = PrimType Metadata
+ , typedValue = ValMd (ValMdDebugInfo di)
+ }
+
nameNode :: Bool -> Bool -> Int -> MetadataTable -> MetadataTable
nameNode fnLocal isDistinct ix mt = mt
{ mtNodes = IntMap.insert ix (fnLocal,isDistinct,mtNextNode mt) (mtNodes mt)
@@ -336,8 +343,7 @@ unnamedEntries pm = bimap Seq.fromList Seq.fromList (partitionEithers (mapMaybe
lookupNode ref d ix = do
tv <- lookupValueTableAbs ref (mtEntries mt)
case tv of
- Typed { typedValue = ValMd v } -> do
- guard (not (mustAppearInline v))
+ Typed { typedValue = ValMd v } ->
pure $! PartialUnnamedMd
{ pumIndex = ix
, pumValues = v
@@ -345,14 +351,6 @@ unnamedEntries pm = bimap Seq.fromList Seq.fromList (partitionEithers (mapMaybe
}
_ -> error "Impossible: Only ValMds are stored in mtEntries"
- -- DIExpressions and DIArgLists are always printed inline and should never be
- -- printed in the global list of unnamed metadata. See
- -- https://github.com/llvm/llvm-project/blob/65600cb2a7e940babf6c493503b9d3fd19f8cb06/llvm/lib/IR/AsmWriter.cpp#L1242-L1245
- mustAppearInline :: PValMd -> Bool
- mustAppearInline (ValMdDebugInfo (DebugInfoExpression{})) = True
- mustAppearInline (ValMdDebugInfo (DebugInfoArgList{})) = True
- mustAppearInline _ = False
-
type InstrMdAttachments = Map.Map Int [(KindMd,PValMd)]
type PKindMd = Int
@@ -996,9 +994,9 @@ parseMetadataEntry vt mt pm (fromEntry -> Just r) =
(addDebugInfo isDistinct (DebugInfoLocalVariable dilv)) pm
29 -> label "METADATA_EXPRESSION" $ do
- isDistinct <- parseField r 0 nonzero
+ _isDistinct <- parseField r 0 nonzero
diExpr <- DebugInfoExpression . DIExpression <$> parseFields r 1 numeric
- return $! updateMetadataTable (addDebugInfo isDistinct diExpr) pm
+ return $! updateMetadataTable (addMdDebugInfo diExpr) pm
30 -> label "METADATA_OBJC_PROPERTY" $ do
-- TODO
@@ -1138,17 +1136,8 @@ parseMetadataEntry vt mt pm (fromEntry -> Just r) =
dial <- DIArgList
<$> (map (mdForwardRef cxt mt) <$> parseFields r 0 numeric)
return $! updateMetadataTable
- -- Unlike most other forms of metadata, METADATA_ARG_LIST never updates
- -- the @IsDistinct@ value. At least, that's my reading of the source
- -- code here:
- -- https://github.com/llvm/llvm-project/blob/8bad4ae679df6fc7dbd016dccbd3da34206e836b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp#L2142-L2158
- --
- -- As a result, we use False below, which is the default value of
- -- IsDistinct set here. It doesn't actually matter that much whether it
- -- is True or False, since we filter out DIArgLists from the list of
- -- global unnamed metadata entries anyway (see `unnamedEntries`). As
- -- such, the value of IsDistinct is never used for anything meaningful.
- (addDebugInfo False (DebugInfoArgList dial)) pm
+ (addMdDebugInfo (DebugInfoArgList dial)) pm
+
code -> fail ("unknown record code: " ++ show code) This passes |
I asked about this on the LLVM Discord, and they agree that |
Instead, put them in `mtEntries`, which aren't used when populating top-level metadata lists. For more information, see the new `Note [Printing metadata inline]`. Fixes #222. This is currently marked as a draft pending some issues with the `smallprog.ll` test case that I added, which still need to be investigated.
Apple's fork of LLVM uses an ever-so-slightly different bitcode format than the upstream version of LLVM. In particular, it adds an additional record to `METADATA_DERIVED_TYPE`, which means that we must be slightly more permissive during parsing to allow Apple LLVM bitcodes through. See the new `Note [Apple LLVM]` for a slightly more detailed explanation. As that Note explains, this is good enough for now, but we may want to think about a more robust solution in the future. I have added an `apple-llvm.bc` regression test to `disasm-test`, but it doesn't yet pass the test suite for unrelated reasons documented in #222. I have added a `known_bugs` entry for this test case until that issue is resolved. Fixes #235.
Apple's fork of LLVM uses an ever-so-slightly different bitcode format than the upstream version of LLVM. In particular, it adds an additional record to `METADATA_DERIVED_TYPE`, which means that we must be slightly more permissive during parsing to allow Apple LLVM bitcodes through. See the new `Note [Apple LLVM]` for a slightly more detailed explanation. As that Note explains, this is good enough for now, but we may want to think about a more robust solution in the future. I have added an `apple-llvm.bc` regression test to `disasm-test`, but it doesn't yet pass the test suite for unrelated reasons documented in #222. I have added a `known_bugs` entry for this test case until that issue is resolved. Fixes #235.
Instead, put them in `mtEntries`, which aren't used when populating top-level metadata lists. For more information, see the new `Note [Printing metadata inline]`. Fixes #222. This is currently marked as a draft pending some issues with the `smallprog.ll` test case that I added, which still need to be investigated.
Instead, put them in `mtEntries`, which aren't used when populating top-level metadata lists. For more information, see the new `Note [Printing metadata inline]`. Fixes #222. This also allows us to remove some `known_bugs` files.
Instead, put them in `mtEntries`, which aren't used when populating top-level metadata lists. For more information, see the new `Note [Printing metadata inline]`. Fixes #222. This also allows us to remove some `known_bugs` files.
Instead, put them in `mtEntries`, which aren't used when populating top-level metadata lists. For more information, see the new `Note [Printing metadata inline]`. Fixes #222. This also allows us to remove some `known_bugs` files.
With the change from 68d26a5 there is a regression that affects debug information. This was noticed in a client of this library when file and line information for functions was no longer available and tracked down to the
guard
statement in this identified commit.It appears that this causes some internal structure synchronization issues of some kind. I will work on the test case more, but I added a smallprog.c file (compile via
clang
with-c -emit-llvm -O0 -g
and then usellvm-disasm
) which exhibits this metadata issue. In the previous implementation (without the guard), the following metadata is observed:With the newer code with the
guard
statement in place, the output changes:Note in particular that there are two
!32
entries now, where the original!33
entry is now preceding the original!32
entry with the same label.It does not appear to be possible to compare this to
llvm-dis
output from LLVM itself because the metadata mapping appears to be somewhat different, although there are not duplicates in thellvm-dis
output either.The text was updated successfully, but these errors were encountered: