-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[5.5/10] arch/arm, cmake: Build FDPIC modules in the normal ELF build. #19940
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
base: master
Are you sure you want to change the base?
Changes from all commits
a14b13f
9de392c
17d795e
9ffc643
74b68a4
6f93388
71203a9
f87df9c
fb2ce4c
f5baea6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,17 +27,67 @@ nuttx_mod_compile_options(-fvisibility=hidden -mlong-calls) | |
| nuttx_elf_compile_options_ifdef(CONFIG_UNWINDER_ARM -fno-unwind-tables | ||
| -fno-asynchronous-unwind-tables) | ||
|
|
||
| # An ELF module needs r9 as its PIC base, so it must not also have the register | ||
| # fixed: GCC rejects that pair with "unable to use 'r9' for PIC register". This | ||
| # mirrors CELFFLAGS in common/Toolchain.defs, which filters --fixed-r9 back out | ||
| # of the inherited CFLAGS for the same reason. | ||
| # -fno-use-cxa-atexit, because the default registers each static object's | ||
| # destructor with __cxa_atexit(dtor, obj, &__dso_handle), and __dso_handle comes | ||
| # from crtbegin, which a module does not link. Turning it off also puts the | ||
| # destructors in .fini_array, which is where the loader looks for them when the | ||
| # module is unloaded. This mirrors CXXELFFLAGS in common/Toolchain.defs. | ||
|
|
||
| nuttx_elf_compile_options_ifdef(CONFIG_PIC -mpic-register=r9) | ||
| nuttx_elf_compile_options(-fno-use-cxa-atexit) | ||
|
|
||
| nuttx_elf_link_options_ifdef( | ||
| CONFIG_PIC --unresolved-symbols=ignore-in-object-files --emit-relocs) | ||
| if(CONFIG_FDPIC) | ||
|
|
||
| nuttx_elf_link_options_ifdef(CONFIG_BINFMT_ELF_RELOCATABLE -r) | ||
| # An FDPIC module is a shared object whose two segments the loader places | ||
| # independently. The stock compiler emits correct FDPIC objects for both C | ||
| # and C++, so only the link needs the arm-uclinuxfdpiceabi linker: the stock | ||
| # one carries the armelf emulation alone and would turn every import into a | ||
| # jump slot where the ABI wants a function descriptor. | ||
|
|
||
| if(NOT FDPIC_CROSSDEV) | ||
| set(FDPIC_CROSSDEV arm-uclinuxfdpiceabi-) | ||
| endif() | ||
|
|
||
| # Say which linker is missing rather than failing later with a command that | ||
| # cannot be run. | ||
|
|
||
| find_program(FDPIC_LD "${FDPIC_CROSSDEV}ld") | ||
|
|
||
| if(NOT FDPIC_LD) | ||
| message( | ||
| FATAL_ERROR | ||
| "CONFIG_FDPIC needs ${FDPIC_CROSSDEV}ld, which is not on PATH. " | ||
| "It is in the NuttX CI image, and tools/ci/docker/linux/Dockerfile " | ||
| "shows how it is built. Set FDPIC_CROSSDEV to use a different prefix") | ||
| endif() | ||
|
|
||
| set(CMAKE_ELF_LD | ||
| "${FDPIC_LD}" | ||
| CACHE INTERNAL "Linker for FDPIC modules") | ||
|
|
||
| nuttx_elf_compile_options(-mfdpic -fPIC -Wa,--noexecstack) | ||
|
|
||
| nuttx_elf_link_options(-m armelf_linux_fdpiceabi -shared -z now) | ||
|
|
||
| else() | ||
|
|
||
| # An ELF module needs r9 as its PIC base, so it must not also have the | ||
| # register fixed: GCC rejects that pair with "unable to use 'r9' for PIC | ||
| # register". This mirrors CELFFLAGS in common/Toolchain.defs, which filters | ||
| # --fixed-r9 back out of the inherited CFLAGS for the same reason. | ||
|
|
||
| nuttx_elf_compile_options_ifdef(CONFIG_PIC -mpic-register=r9) | ||
|
|
||
| nuttx_elf_link_options_ifdef( | ||
| CONFIG_PIC --unresolved-symbols=ignore-in-object-files --emit-relocs) | ||
|
|
||
| endif() | ||
|
|
||
| # Not with CONFIG_PIC: there the module is linked as an executable, which is | ||
| # what common/Toolchain.defs does too. | ||
|
|
||
| if(CONFIG_BINFMT_ELF_RELOCATABLE AND NOT CONFIG_PIC) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why need check pic |
||
| nuttx_elf_link_options(-r) | ||
| endif() | ||
|
|
||
| nuttx_mod_link_options(-r) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -633,16 +633,58 @@ CELFFLAGS = $(filter-out --fixed-r9,$(CFLAGS)) -fvisibility=hidden \ | |
| CXXELFFLAGS = $(filter-out --fixed-r9,$(CXXFLAGS)) -fvisibility=hidden \ | ||
| -mlong-calls | ||
|
|
||
| # -fno-use-cxa-atexit, because the default registers each static object's | ||
| # destructor with __cxa_atexit(dtor, obj, &__dso_handle), and __dso_handle | ||
| # comes from crtbegin, which a module does not link. Turning it off also | ||
| # puts the destructors in .fini_array, which is where the loader looks for | ||
| # them when the module is unloaded. | ||
|
|
||
| CXXELFFLAGS += -fno-use-cxa-atexit | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need modify cmakefile and other arch |
||
|
|
||
| ifeq ($(CONFIG_PIC),y) | ||
| # ARCHCFLAGS, not CFLAGS: board Make.defs reassign CFLAGS with ':=' | ||
| # after including this file, which would discard the flag. | ||
|
|
||
| ARCHCFLAGS += --fixed-r9 | ||
|
|
||
| ifeq ($(CONFIG_FDPIC),y) | ||
| # An FDPIC module is a shared object whose two segments the loader places | ||
| # independently. The stock compiler emits correct FDPIC objects for both C | ||
| # and C++, so only the link needs the arm-uclinuxfdpiceabi linker: the | ||
| # stock one carries the armelf emulation alone and would turn every import | ||
| # into a jump slot where the ABI wants a function descriptor. | ||
|
|
||
| FDPIC_CROSSDEV ?= arm-uclinuxfdpiceabi- | ||
| MODULELD = $(FDPIC_CROSSDEV)ld | ||
|
|
||
| # Say which linker is missing rather than letting make report a command it | ||
| # cannot run. The report is deferred to the link itself rather than made | ||
| # here, so that a tree configured for FDPIC on a host without the linker can | ||
| # still be cleaned and reconfigured. | ||
|
|
||
| FDPIC_LD_FOUND := $(shell command -v $(MODULELD) 2> /dev/null) | ||
|
|
||
| ifeq ($(FDPIC_LD_FOUND),) | ||
| FDPIC_NO_LD_MSG = CONFIG_FDPIC needs $(FDPIC_CROSSDEV)ld, which is not \ | ||
| on PATH. It is in the NuttX CI image, and \ | ||
| tools/ci/docker/linux/Dockerfile shows how it is built. Set \ | ||
| FDPIC_CROSSDEV to use a different prefix. | ||
|
|
||
| MODULELD = $(SHELL) -c 'echo "ERROR: $(FDPIC_NO_LD_MSG)" 1>&2; exit 1' -- | ||
| endif | ||
|
|
||
| CELFFLAGS += -mfdpic -fPIC -Wa,--noexecstack | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not reference PICFLAGS |
||
| CXXELFFLAGS += -mfdpic -fPIC -Wa,--noexecstack | ||
|
|
||
| LDELFFLAGS += -m armelf_linux_fdpiceabi -shared -z now | ||
| else | ||
| CELFFLAGS += $(PICFLAGS) -mpic-register=r9 | ||
| CXXELFFLAGS += $(PICFLAGS) -mpic-register=r9 | ||
|
|
||
| # Generate an executable elf, need to ignore undefined symbols | ||
| LDELFFLAGS += --unresolved-symbols=ignore-in-object-files --emit-relocs | ||
| endif | ||
|
|
||
| else | ||
| ifneq ($(CONFIG_BINFMT_ELF_EXECUTABLE),y) | ||
| LDELFFLAGS += -r | ||
|
|
||
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.
add if CONFIG_PIC and remove ifdef suffix at line 65 and 67