Skip to content

Make: fix use of gcc as LD for modules and ELF executables builds - #4173

Merged
acassis merged 1 commit into
apache:masterfrom
ppisa:adjust-elf-and-module-to-use-gcc-as-ld
Jul 19, 2021
Merged

acassis merged 1 commit into
apache:masterfrom
ppisa:adjust-elf-and-module-to-use-gcc-as-ld

Conversation

@ppisa

@ppisa ppisa commented Jul 18, 2021

Copy link
Copy Markdown
Contributor

Summary

The patch

Make: use gcc as LD

introduced use of GCC wrapper as linker. LD variable references GCC
executable now. But when GCC wrapper s used to build relocatable
loadable objects (ELF executables and modules) then it causes
linking of toolchain default libc and other libraries even when -r
is usd. Another problem is that incorrect multiarch variant is selected
for libraries search and possibly even for LTO or C++ templates
instantiating and other glue code which causes fails during linking
if CFLAGS selects non/default miltiarch variant.

Corresponding CFLAGS are passed to LDMODULEFLAGS and LDELFFLAGS
as well as -nostartfiles -nodefaultlibs options.

Separate line is used to easily find and adjust lines if link
process is changed in future.

Signed-off-by: Pavel Pisa [email protected]

Impact

Testing

Tested on LX_CPU board

tools/configure.sh lx_cpu:nsh

This board default config enables ELF and MODULES which results
in the build errors

/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: error:
chardev.o uses VFP register arguments, chardev does not
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: failed to
merge target specific data of file chardev.o
collect2: error: ld returned 1 exit status

If only CFLAGS are added then linking of GCC/Newlib provided CRT0 and LIBC
causes attempt t export symbols which are not provided by NuttX build and build
fails in the linking phase.

@ppisa
ppisa force-pushed the adjust-elf-and-module-to-use-gcc-as-ld branch 2 times, most recently from a1b1495 to 1b59921 Compare July 18, 2021 18:27
The patch

  Make: use gcc as LD

introduced use of GCC wrapper as linker. LD variable references GCC
executable now. But when GCC wrapper s used to build relocatable
loadable objects (ELF executables and modules) then it causes
linking of toolchain default libc and other libraries even when -r
is usd. Another problem is that incorrect multiarch variant is selected
for libraries search and possibly even for LTO or C++ templates
instantiating and other glue code which causes fails during linking
if CFLAGS selects non/default miltiarch variant.

Corresponding CFLAGS are passed to LDMODULEFLAGS and LDELFFLAGS
as well as -nostartfiles -nodefaultlibs options.

Separate line is used to easily find and adjust lines if link
process is changed in future.

Signed-off-by: Pavel Pisa <[email protected]>
@ppisa
ppisa force-pushed the adjust-elf-and-module-to-use-gcc-as-ld branch from 1b59921 to 1702aa0 Compare July 18, 2021 23:35
@ppisa
ppisa marked this pull request as ready for review July 19, 2021 09:37
@acassis
acassis merged commit 6c2c70c into apache:master Jul 19, 2021
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