Closed chen-png closed 2 years ago
@tejlmand your input appreciated.
@tejlmand Could you tell me the purpose of this two line?
. = 0x0; . = ALIGN(4);
it's from a generated liner script "snippets-rom-start.ld", I am curious why we need to set the location counter to 0x0, because the RAM region it starts from 0x100000, this will meet a location counter move backwards error.
not sure why this "snippets-rom-start.ld" linker script for ROM is there, but for this case, it should does not matter. because that linker script is used for putting .text section into ROM, but in this case, we put .text in RAM, so I removed it, then it didn't report any move backwards error or overflow error. tested on qemu_x86, qemu_x86_64, built a hello_word and it worked well.
it's from a generated liner script "snippets-rom-start.ld", I am curious why we need to set the location counter to 0x0, because the RAM region it starts from 0x100000, this will meet a location counter move backwards error.
This originates from here, and is default included in the snippets-rom-start.ld
:
https://github.com/zephyrproject-rtos/zephyr/blob/875ec0a0cb02d261f758adf2d0f6a01ca566b4df/arch/common/rom_start_offset.ld#L7-L8
but the x86 doesn't place its text in rom, as it don't have a FLASH memory region.
Seems lld
is a bit more pedantic on this than ld
on this.
One trick, is to set the rom offset == 0x100000, like this:
-DCONFIG_ROM_START_OFFSET=0x100000
This will fix both the overflow error and the location counter moving backwards. We should look into if this snippet make sense for x86: https://github.com/zephyrproject-rtos/zephyr/blob/875ec0a0cb02d261f758adf2d0f6a01ca566b4df/include/arch/x86/ia32/linker.ld#L94
it probably does, but then we should ensure it behaves properly.
Describe the bug when tried to use LLVM built-in lld linker to build zephyr case, it met a link error "section 'boot.text' will not fit in region 'RAM': overflowed by 18446744072631615488 bytes"
To Reproduce Steps to reproduce the behavior:
apply this patch, it's used for forcing llvm to use lld and solving option compatibility between ld and lld.
+config LLVM_USE_BUILTIN_LLD
config HAVE_CUSTOM_LINKER_SCRIPT bool "Custom linker script provided" help diff --git a/cmake/linker/ld/target_base.cmake b/cmake/linker/ld/target_base.cmake index 1fec5ca96f..69a008b17a 100644 --- a/cmake/linker/ld/target_base.cmake +++ b/cmake/linker/ld/target_base.cmake @@ -24,8 +24,15 @@ macro(toolchain_ld_base)
in descending order to minimize padding between these symbols.
zephyr_ld_option_ifdef( CONFIG_LINKER_SORT_BY_ALIGNMENT
--sort-common option of lld is not compatible with ld, so remove
it when using lld.
endif()
endmacro() diff --git a/cmake/linker/lld/target.cmake b/cmake/linker/lld/target.cmake index e9ac00ff96..376a26b680 100644 --- a/cmake/linker/lld/target.cmake +++ b/cmake/linker/lld/target.cmake @@ -11,6 +11,9 @@ macro(configure_linker_script linker_script_gen linker_pass_define) set(extra_dependencies ${ARGN}) set(template_script_defines ${linker_pass_define}) list(TRANSFORM template_script_defines PREPEND "-D")
endif()
Different generators deal with depfiles differently.
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") diff --git a/cmake/linker/lld/target_baremetal.cmake b/cmake/linker/lld/target_baremetal.cmake index 76965ed81b..0b315828cb 100644 --- a/cmake/linker/lld/target_baremetal.cmake +++ b/cmake/linker/lld/target_baremetal.cmake @@ -11,6 +11,12 @@ macro(toolchain_ld_baremetal) ${LINKERFLAGPREFIX},-X ${LINKERFLAGPREFIX},-N )
Force LLVM to use built-in linker lld
endif()
Funny thing is if this is set to =error, some architectures will
skip this flag even though the compiler flag check passes
diff --git a/include/linker/linker-tool.h b/include/linker/linker-tool.h index 352cc5f60e..2c1ea7508c 100644 --- a/include/linker/linker-tool.h +++ b/include/linker/linker-tool.h @@ -17,6 +17,13 @@
if defined(_LINKER)
if defined(GCC_LINKER_CMD)
+/* ALIGN_WITH_INPUT is not supported by LLVM lld,
include <linker/linker-tool-gcc.h>
elif defined(MWDT_LINKER_CMD)
include <linker/linker-tool-mwdt.h>
Logs and console output [83/97] Linking C executable zephyr/zephyr_pre0.elf FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /home/chenpeng/zephyrproject/zephyr/build/zephyr/zephyr_pre0.map : && ccache /home/chenpeng/llvm/llvm-project/build_2/bin/clang --target=i686-pc-none-elf zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf zephyr/CMakeFiles/offsets.dir/./arch/x86/core/offsets/offsets.c.obj -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=/home/chenpeng/zephyrproject/zephyr/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/arch/x86/core/libarchx86core.a zephyr/lib/libc/minimal/libliblibcminimal.a zephyr/lib/posix/liblibposix.a zephyr/subsys/random/libsubsysrandom.a zephyr/drivers/interrupt_controller/libdrivers__interrupt_controller.a zephyr/drivers/console/libdriversconsole.a zephyr/drivers/serial/libdriversserial.a zephyr/drivers/timer/libdrivers__timer.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a -L"/usr/lib64/gcc/x86_64-redhat-linux/9/32" -L/home/chenpeng/zephyrproject/zephyr/build/zephyr -lgcc -no-pie -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -fuse-ld=lld -Wl,--orphan-handling=warn && cd /home/chenpeng/zephyrproject/zephyr/build/zephyr && /home/chenpeng/.local/lib/python3.7/site-packages/cmake/data/bin/cmake -E echo clang-13: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument] ld.lld: warning::(.eh_frame) is being placed in '.eh_frame'
ld.lld: warning: :(.symtab) is being placed in '.symtab'
ld.lld: warning: :(.shstrtab) is being placed in '.shstrtab'
ld.lld: warning: :(.strtab) is being placed in '.strtab'
ld.lld: error: no memory region specified for section '.eh_frame'
ld.lld: error: zephyr/linker_zephyr_pre0.cmd:101: unable to move location counter backward for: text
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705357312 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705357312 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705357473 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705357754 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358093 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358098 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358121 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358134 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358149 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358191 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358239 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358523 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705358605 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705359498 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705359722 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705359870 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705359900 bytes
ld.lld: error: section 'text' will not fit in region 'RAM': overflowed by 18446744073705359914 bytes
ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
collect2: error: ld returned 1 exit status
clang-13: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /home/chenpeng/.local/bin/cmake --build /home/chenpeng/zephyrproject/zephyr/build
Part of code of liner script linker_zephyr_pre0.cmd:
Environment (please complete the following information):