This is an archive of the discontinued LLVM Phabricator instance.

Do not call exit() directly from lld.
ClosedPublic

Authored by ruiu on May 4 2018, 11:15 AM.

Details

Summary

Our promise is that as long as there's no fatal error (i.e. broken
file is given to the linker), our main function returns to the caller.
So we can't use exit() in the regular code path.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

ruiu created this revision.May 4 2018, 11:15 AM

If we use return (instead of exit) as in this patch, the final params file( Config->ThinLTOIndexOnlyObjectsFile) is not fully generated and few of the last entries are not written(even though respective files are generated) . Here _exit() is called eventually from exitLld function call in elf::link . However, if we replace that with exit(), the file is generated properly. From here, it seems that _exit() is not able to close the file properly.

ruiu added a comment.May 4 2018, 3:01 PM

_exit() doesn't flush the buffer indeed. So it is likely that the LTO object holds file handles until it is destroyed. Maybe we should call the destructor before returning. Let me try that.

Do you know how I can test it?

ruiu updated this revision to Diff 145550.May 7 2018, 2:36 PM
  • flush IndexFile before returning so that the file is not truncated.
pcc accepted this revision.May 7 2018, 2:58 PM

LGTM

This revision is now accepted and ready to land.May 7 2018, 2:58 PM
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.