]> granicus.if.org Git - llvm/commit
Avoid using unspecified ordering in MetadataLoader::MetadataLoaderImpl::parseOneMetadata.
authorIvan Krasin <krasin@chromium.org>
Fri, 27 Jan 2017 15:54:49 +0000 (15:54 +0000)
committerIvan Krasin <krasin@chromium.org>
Fri, 27 Jan 2017 15:54:49 +0000 (15:54 +0000)
commitccbf1f72a6bb103ca6fb701e713a93bbd657f7fc
tree004e2d39e2466140a4c271ba0dd9ca3695f1415a
parent93c31fb5c9b6e8a7d01fa35b41e4f878a8d1be50
Avoid using unspecified ordering in MetadataLoader::MetadataLoaderImpl::parseOneMetadata.

Summary:
MetadataLoader::MetadataLoaderImpl::parseOneMetadata uses
the following construct in a number of places:

```
MetadataList.assignValue(<...>, NextMetadataNo++);
```

There, NextMetadataNo gets incremented, and since the order
of arguments evaluation is not specified, that can happen
before or after other arguments are evaluated.

In a few cases the other arguments indirectly use NextMetadataNo.
For instance, it's

```
MetadataList.assignValue(
    GET_OR_DISTINCT(DIModule,
                    (Context, getMDOrNull(Record[1]),
                     getMDString(Record[2]), getMDString(Record[3]),
                     getMDString(Record[4]), getMDString(Record[5]))),
    NextMetadataNo++);
```

getMDOrNull calls getMD that uses NextMetadataNo:

```
MetadataList.getMetadataFwdRef(NextMetadataNo);
```

Therefore, the order of evaluation becomes important. That caused
a very subtle LLD crash that only happens if compiled with GCC or
if LLD is built with LTO. In the case if LLD is compiled with Clang
and regular linking mode, everything worked as intended.

This change extracts incrementing of NextMetadataNo outside of
the arguments list to guarantee the correct order of evaluation.

For the record, this has taken 3 days to track to the origin. It all
started with a ThinLTO bot in Chrome not being able to link a target
if debug info is enabled.

Reviewers: pcc, mehdi_amini

Reviewed By: mehdi_amini

Subscribers: aprantl, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293291 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Bitcode/Reader/MetadataLoader.cpp