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
Fix native_posix build on Debian #38903
Conversation
@yashi This fixes the issue on my device. Could you give it a try? |
Set as draft, it seems to break other builds. I'll keep playing around with these flags. |
it's most likely related to this binutils commit: but note, this is only a linker |
70ecd1f
to
2057b0b
Compare
I also considered putting this under |
I've missed this somehow. I'll find time to test it today. meanwhile,
Is this really true? I see GCC info has |
You're right about Easiest reference I've been looking at is at https://man7.org/linux/man-pages/man1/gcc.1.html, do you have a better one? |
How about something like this: diff --git a/cmake/linker/ld/target_baremetal.cmake b/cmake/linker/ld/target_baremetal.cmake
index 36ec3c14d8..76965ed81b 100644
--- a/cmake/linker/ld/target_baremetal.cmake
+++ b/cmake/linker/ld/target_baremetal.cmake
@@ -8,7 +8,6 @@ macro(toolchain_ld_baremetal)
zephyr_ld_options(
-nostdlib
-static
- -no-pie
${LINKERFLAGPREFIX},-X
${LINKERFLAGPREFIX},-N
)
diff --git a/cmake/linker/ld/target_base.cmake b/cmake/linker/ld/target_base.cmake
index 0eee30ea85..1fec5ca96f 100644
--- a/cmake/linker/ld/target_base.cmake
+++ b/cmake/linker/ld/target_base.cmake
@@ -11,6 +11,7 @@ macro(toolchain_ld_base)
# TOOLCHAIN_LD_FLAGS comes from compiler/gcc/target.cmake
# LINKERFLAGPREFIX comes from linker/ld/target.cmake
zephyr_ld_options(
+ -no-pie
${TOOLCHAIN_LD_FLAGS}
)
We unconditionally set |
That works on my machine, update the PR and we'll see what the CI thinks :) |
CMakeLists.txt
Outdated
@@ -302,7 +302,6 @@ zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp, | |||
include(cmake/extra_flags.cmake) | |||
|
|||
zephyr_cc_option(-fno-asynchronous-unwind-tables) | |||
zephyr_cc_option(-fno-pie) |
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.
Why do you want to remove this?
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.
Isn't it now added in ld/target_base.cmake anyway? Did I misunderstand how that .cmake
file gets included?
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.
Update -fno-pie to only be added when relevant. This fixes native_posix builds on Debian hosts.
This doesn't describe what the error is nor why we add this change. A few points we should make in the commit log are:
- Debian and other Linux distributions have
ld
with--warn-textrel
as default. - The option generates a warning when linking on x86.
- The warning make
scripts/twister
fail because we treat all warnings as error. - The warning is issued when no PIE objects are linked against PIE library.
- PIE (Position Independent Executable) or not can be seen with the following command.
- When you want to generate non PIE, link with
-no-pie
.
Non PIE
$ readelf -l build/zephyr/zephyr.elf | grep 'Elf file type is'
Elf file type is EXEC (Executable file)
PIE
$ readelf -l /lib/x86_64-linux-gnu/libc.so.6 | grep 'Elf file type is'
Elf file type is DYN (Shared object file)
Done, I added this content. Sorry, I assumed all the rest of the info could be found by following the issue link. |
Update -fno-pie to only be added when relevant. This fixes native_posix builds on Debian hosts. * Debian and other Linux distributions have ld with --warn-textrel as default. * The option generates a warning when linking on x86. * The warning make scripts/twister fail because we treat all warnings as error. * The warning is issued when no PIE objects are linked against PIE library. * PIE (Position Independent Executable) or not can be seen with the following command. * When you want to generate non PIE, link with `-no-pie.` Non PIE $ readelf -l build/zephyr/zephyr.elf | grep 'Elf file type is' Elf file type is EXEC (Executable file) PIE $ readelf -l /lib/x86_64-linux-gnu/libc.so.6 | \ grep 'Elf file type is' Elf file type is DYN (Shared object file) Issue zephyrproject-rtos#35244 Signed-off-by: Yuval Peress <peress@google.com>
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.
lgtm
See also zephyrproject-rtos#38903 This is required when building tests for native_posix on ubuntu 22.04 using clang-14 from the normal deb repository. Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
See also zephyrproject-rtos#38903 This is required when building tests for native_posix on ubuntu 22.04 using clang-14 from the normal deb repository. Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com> (cherry picked from commit 017fdc0a8769ab15172ad11e951ed9be1184d631)
See also #38903 This is required when building tests for native_posix on ubuntu 22.04 using clang-14 from the normal deb repository. Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
See also zephyrproject-rtos/zephyr#38903 This is required when building tests for native_posix on ubuntu 22.04 using clang-14 from the normal deb repository. (cherry picked from commit 1fde62e) Original-Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com> GitOrigin-RevId: 1fde62e Change-Id: I76cfb2bbd71df1ffb137b681b648320081f9f046 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4047582 Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com> Reviewed-by: Yuval Peress <peress@google.com> Tested-by: CopyBot Service Account <copybot.service@gmail.com> Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com> Reviewed-by: Keith Short <keithshort@chromium.org> Tested-by: Yuval Peress <peress@google.com> Tested-by: Fabio Baltieri <fabiobaltieri@google.com> Tested-by: Keith Short <keithshort@chromium.org>
See also zephyrproject-rtos/zephyr#38903 This is required when building tests for native_posix on ubuntu 22.04 using clang-14 from the normal deb repository. Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
Debian (by default) enables PIE/PIC and the flag to override it doesn't
use the 'f' prefix. This is fixed by also adding -no-pie and -no-pic
to the zephyr_cc_options.
Issue #35244
Signed-off-by: Yuval Peress peress@google.com