chore: amd64 and arm64 use PIE build mode by default #272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Usage:
Added the feature of setting BUILD_MODE according to GOARCH in Makefile
I added some code in Makefile to set different BUILD_MODE values according to different GOARCH values, so as to achieve cross-platform compilation and position-independent executable files. This allows the program to run on different operating systems and computing architectures, and also improves the security of the program. This PR is to enhance the compatibility and stability of the project.
I specifically specified that only when GOARCH is amd64 or arm64, -buildmode=pie will be used to set BUILD_MODE. This is because pie may not be supported on other computing architectures. Therefore, I used an ifeq statement to judge the value of GOARCH and set BUILD_MODE according to different situations.
I also added a feature that allows users to manually specify the build mode using make BUILD_MODE=-buildmode=*, overriding the default settings. This allows users to choose the appropriate build mode according to their needs, such as , pie, c-shared, c-archive, shared, plugin, etc. If the user does not manually specify the build mode, then if GOARCH is amd64 or arm64, -buildmode=pie will be used.
Checklist
Full Changelogs
Issue Reference
Fix #[issue number]
Test Result
I used different GOARCH and BUILD_MODE values to compile the project and run tests on amd64 and arm64 platforms. The test results show that my modification can correctly set BUILD_MODE and does not affect the normal operation of other parameters and functions.
test code:
result: