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
Refactor to fixed width integer types: proven to be free of errors #268
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great PR. I strongly prefer types like int_32_t
over types like int
. I tested this on NixOS 23.11, and I was indeed able to produce identical object files and executable files.
However, to make a build deterministic, you must define D3_GIT_HASH as something constant and it must be a Release build. This is how I built each one.
echo "#undef D3_GIT_HASH" >> lib/d3_version.h.in echo "#define D3_GIT_HASH \"\"" >> lib/d3_version.h.in cmake --preset linux cmake --build --preset linux --config Release
Instead of modifying lib/d3_version.h.in
, I used nix-shell --pure
in order to make sure that git
was not on my PATH
. It would be nice if we could run cmake -D GIT_HASH="whatever"
, but that’s a topic for another pull request.
I have a few questions/suggestions:
- I don’t think that “standard types” is the right term here. I know that the header is called “cstdint”, but I don’t think that “standard” is a good way of describing these types, especially because they seem to be less common than
char
,short
,int
, etc. I would rename this PR to “Refactor to fixed-width types: proven to be free of errors”. - Does your script prove that the generated
.so
files are identical? - I have a few very minor suggestions for your script:
- It looks like the indentation for your for loop got messed up.
- I would replace
$(find -type f | grep -E "\.o$")
with$(find -type f -name '*.o')
. - Why did you decide to calculate hashes for the executables instead of using
diff
like you did for the.o
files?
At this point, updating the scripting any further is code golf because |
Thanks, but this will not be reviewed for a while. We are currently working on importing icculus' diffs from the 2020 linux and mac ports of this game and then bringing windows up to feature parity--as a result, we're avoiding large-scale code changes for now to help prevent conflicts. Other refactors are not on the docket at the moment. I understand this somewhat changes the "1.5 stable release" milestone--this will be expanded on in the coming weekly update. If you would like, keep this as a draft. Otherwise, we can revisit later. |
The entire point of proving that it builds identical binaries as before the changes was to ensure that no manual review was required. |
Pull Request Type
Description
Changes non-specific types (e.g.
unsigned int
) to their stdint specified counterparts (e.g. uint32_t).I avoided modifying anything that could have the the "long" keyword as part of it because of 64-bit compatibility issues that have been fully addressed. See also: #233
Yes, this is is a massive refactor and looking at every line is a waste of time but I have proven that no errors were introduced in the process. I did this by comparing the object code and executables generated before and after the patches were applied. By ensuring the binary files were identical, it's a certainty that no errors were introduced.
However, to make a build deterministic, you must define D3_GIT_HASH as something constant and it must be a Release build. This is how I built each one.
here's the script, to compare object code, libraries and binaries files.
output:
Checklist
Additional Comments