Detect when linking a binary has finished by looking at just the executable?

69 Views Asked by At

The build tool for the language in which our project is written does compilation and linking in parallel, for a number of different binaries and so on. In CI we have a separate thread that looks for these compiled binaries as they become available and kicks off other processes.

The trouble is it seems that just waiting for the file to exist and become chmod a+x is not enough, and sometimes we end up uploading corrupt binaries.

Is there any way to determine, just by looking at a file, whether linking has finished? This can be specific to x86-64, and even just specific to gold or lld.

(My fallback solution is to create a shim around the linker that we use, that can signal in some way when it's actually complete)

2

There are 2 best solutions below

2
On BEST ANSWER

While the linker output file is open then the linker is not finished. The approach I would use is to check whether the output file is open or not.

See Is there a way to check if a file is in use?

See as well this post about to an answer about checking a file is open by another process which has a discussion on the problem Determine if file is in the process of being written upon?

0
On

For gold at least, if you ask it to generate a mapfile (-Map filename), the mapfile is produced after the output file has been written and closed. If you wait for the mapfile to be created, then you can be sure that the output file is complete.