This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Support for --build-id=uuid
ClosedPublic

Authored by evgeny777 on Aug 10 2016, 4:49 AM.

Details

Summary

This has to be done differently on Windows and Unix systems.
I ran test suite on Windows, Ubuntu and FreeBSD.

Diff Detail

Repository
rL LLVM

Event Timeline

evgeny777 updated this revision to Diff 67505.Aug 10 2016, 4:49 AM
evgeny777 retitled this revision from to [ELF] Support for --build-id=uuid.
evgeny777 updated this object.
evgeny777 added a reviewer: ruiu.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
evgeny777 added subscribers: grimar, davide, emaste and 2 others.
ruiu added inline comments.Aug 10 2016, 11:09 AM
ELF/OutputSections.cpp
1687 ↗(On Diff #67505)

I'd add code to generate a RNG to LLVM rather than to LLD because it seems generic and should be useful in other places.

ruiu edited edge metadata.Aug 10 2016, 11:09 AM

One more question: is there any project that actually uses this option?

Our project does, but we need only Windows version. We can keep this patch proprietary of course, if it's not desired for some reason

evgeny777 added inline comments.Aug 10 2016, 11:13 AM
ELF/OutputSections.cpp
1687 ↗(On Diff #67505)

You mean creating random GUID, don't you?

ruiu added a comment.Aug 10 2016, 11:22 AM

I asked the question because we do not usually create features just because other linkers have them, so I wanted to confirm that you actually needed it. So there's no problem to add this feature to LLD.

ELF/OutputSections.cpp
1687 ↗(On Diff #67505)

GUID is actually jus random 16 bytes, so maybe adding a function to create a GUID is too narrowly scoped. How about defining a function that returns truely random bytes of any length? Like

std::vector<uint8_t> getRandomBytes(size_t Length);
evgeny777 added inline comments.Aug 10 2016, 11:25 AM
ELF/OutputSections.cpp
1687 ↗(On Diff #67505)

There is a special routine on Windows which should be used to create GUID (UuidCreate). I'm afraid getRandomBytes is too generic for this particular case.

evgeny777 updated this revision to Diff 67826.Aug 12 2016, 5:57 AM
evgeny777 edited edge metadata.
evgeny777 removed rL LLVM as the repository for this revision.

Just curious if using std::mt19937_64 would be easier.

ruiu added a comment.Aug 12 2016, 11:30 AM

I have a concern about using current time as a random source. Even with a nano second resolution timer (and I think timers are in reality not that accurate), there's a small chance for two machines to create two different executables at the same time. If that happens, the two files get the same build-id. That's a small probability but much larger than a collision in 2^128 space.

How about using timer value + Bufs and calculate md5 of the combined value (a sort of hmac-md5)?

ruiu added a comment.Aug 12 2016, 1:39 PM

Maybe you can, but it's still less entropy than real random values, so why don't you just use a true random value such as /dev/random?

evgeny777 updated this revision to Diff 69330.Aug 26 2016, 2:16 AM

Patch to support library landed, so I'm updating diff.

ruiu accepted this revision.Aug 26 2016, 2:51 AM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Aug 26 2016, 2:51 AM
This revision was automatically updated to reflect the committed changes.