Skip to content

Conversation

eramongodb
Copy link
Contributor

@eramongodb eramongodb commented Sep 25, 2025

Followup to #2097, which seems to have somehow broken the hardened-compile task:

/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/Scrt1.o: In function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/libbson/CMakeFiles/bson_shared.dir/build.make:550: src/libbson/libbson2.so.2.2.0] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:1549: src/libbson/CMakeFiles/bson_shared.dir/all] Error 2

My rough understanding of what is happening here is that the explicit -pie linker flag ("position-independent executable") being passed via LDFLAGS was being applied to shared library targets, which is incorrect (not an executable). It's not clear to me which part of #2097 is responsible for exposing this issue (newer CMake version? use of Ninja?). Nevertheless, this PR proposes avoiding the explicit compiler or linker flags by using the CMake CMAKE_POSITION_INDEPENDENT_CODE variable instead, allowing CMake to apply the appropriate flags according to each target.

The only remaining instance of -fPIE in the repo is:

md->flags = bson_strdup("CFLAGS=\"-fPIE\"");

There are no more instances of the -pie flag. There are several instances of explicit -fPIC flags, but replacing these with POSITION_INDEPENDENT_CODE (target property) is deferred to another time (not essential to the goal of this PR).

@eramongodb eramongodb self-assigned this Sep 25, 2025
@eramongodb eramongodb requested a review from a team as a code owner September 25, 2025 20:54
@eramongodb eramongodb merged commit 75abd6d into mongodb:master Sep 26, 2025
44 of 46 checks passed
@eramongodb eramongodb deleted the cdriver-evg-hardened-compile branch September 26, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants