Skip to content

Commit

Permalink
cmake: modules/FindGnuLd: cache variable GNULD_VERSION_STRING
Browse files Browse the repository at this point in the history
This changes to cache variable GNULD_VERSION_STRING across cmake
runs. This variable is used to determine whether -Wl,-no-pie is
being passed to linker. However, if cmake is run multiple times
without clearing the build directory, GNULD_VERSION_STRING was
lost and the script falsely assumed the linker could not take
this argument, and thus omitting it during linking. Depending on
the host, it would warn on something like this:

  /usr/bin/ld.bfd: app/libapp.a(main.c.obj):
      warning: relocation in read-only section
      `.text._posix_zephyr_main'
  /usr/bin/ld.bfd: warning: creating DT_TEXTREL in a PIE

To fix this, simply caches GNULD_VERSION_STRING so it can be
used during subsequent cmake runs.

Fixes #61725

Signed-off-by: Daniel Leung <[email protected]>
  • Loading branch information
dcpleung authored and nashif committed Sep 1, 2023
1 parent 69643d5 commit 2d78cb7
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions cmake/modules/FindGnuLd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ if(GNULD_LINKER)
RESULT_VARIABLE gnuld_status
)

set(GNULD_VERSION_STRING)
if(${gnuld_status} EQUAL 0)
# Extract GNU ld version. Different distros have their
# own version scheme so we need to account for that.
Expand All @@ -90,7 +89,7 @@ if(GNULD_LINKER)
string(REGEX MATCH
"GNU ld \\(.+\\) ([0-9]+[.][0-9]+[.]?[0-9]*).*"
out_var ${gnuld_version_output})
set(GNULD_VERSION_STRING ${CMAKE_MATCH_1})
set(GNULD_VERSION_STRING ${CMAKE_MATCH_1} CACHE STRING "GNU ld version" FORCE)
endif()
endif()

Expand Down

0 comments on commit 2d78cb7

Please sign in to comment.