Skip to content
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

Unify the code of libelf and modlib, and delete the implementation of libelf #14100

Merged
merged 20 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Documentation/guides/coredump.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ Enable Kconfig

.. code-block:: console

CONFIG_ELF=y /* Enable ELF */

CONFIG_ELF_COREDUMP=y /* Enable ELF Coredump */
CONFIG_COREDUMP=y /* Enable Coredump */

CONFIG_BOARD_COREDUMP_SYSLOG=y /* Enable Board Coredump, if exceptions and assertions occur, */

Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden -mlong-calls # --target1-abs
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)

# Zig toolchain

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/src/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden -mlong-calls # --target1-abs
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden -mlong-calls # --target1-abs

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/avr/src/avr/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/avr/src/avr32/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/ceva/src/xc5/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/ceva/src/xm6/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/mips/src/mips32/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/misoc/src/lm32/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/misoc/src/minerva/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/or1k/src/mor1kx/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/risc-v/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ else
LDELFFLAGS += --oformat elf64-littleriscv
endif

LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld)

# Zig toolchain

Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/src/sparc_v8/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
71 changes: 71 additions & 0 deletions arch/x86/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
############################################################################
# arch/x86/src/common/Toolchain.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g3
endif

ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += -O2
endif

ARCHCPUFLAGS = -march=i486 -mtune=i486 -fno-stack-protector
ARCHPICFLAGS = -fpic
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef

# Check if building a 32-bit target with a 64-bit toolchain

ifeq ($(CONFIG_ARCH_X86_M32),y)
ARCHCPUFLAGS += -m32
LDFLAGS += -m elf_i386
endif

# We have to use a cross-development toolchain under Cygwin because the native
# Cygwin toolchains don't generate ELF binaries.

ifeq ($(CONFIG_WINDOWS_CYGWIN),y)
CROSSDEV = i486-nuttx-elf-
endif

CC = $(CROSSDEV)gcc
CPP = $(CROSSDEV)gcc -E -x c
LD = $(CROSSDEV)ld
STRIP = $(CROSSDEV)strip --strip-unneeded
AR = $(CROSSDEV)ar rcs
NM = $(CROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump

CFLAGS := $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__

# Loadable module definitions

CMODULEFLAGS = $(CFLAGS) -fvisibility=hidden
LDMODULEFLAGS = -r -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld)

# ELF module definitions

CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/x86_64/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main --gc-sections
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)

# -fno-pic to avoid GOT relocations
# -mcmodel=large to avoid out-of-range 32-bit relocations
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/src/lx6/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden -mtext-section-literals
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden -mtext-section-literals

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/xtensa/src/lx7/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden -mtext-section-literals
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden -mtext-section-literals

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/z16/src/z16f/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/z80/src/ez80/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/z80/src/z180/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/z80/src/z8/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
2 changes: 1 addition & 1 deletion arch/z80/src/z80/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden

LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
3 changes: 1 addition & 2 deletions binfmt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ list(
binfmt_exec.c
binfmt_copyargv.c
binfmt_copyactions.c
binfmt_dumpmodule.c
binfmt_coredump.c)
binfmt_dumpmodule.c)

if(CONFIG_BINFMT_LOADABLE)
list(APPEND SRCS binfmt_exit.c)
Expand Down
7 changes: 6 additions & 1 deletion binfmt/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ config ELF
default n
select BINFMT_LOADABLE
select LIBC_ARCH_ELF
select LIBC_MODLIB
select ARCH_USE_TEXT_HEAP if ARCH_HAVE_TEXT_HEAP
---help---
Enable support for the ELF binary format. Default: n

if ELF
source "binfmt/libelf/Kconfig"
config ELF_STACKSIZE
int "ELF Stack Size"
default DEFAULT_TASK_STACKSIZE
---help---
This is the default stack size that will be used when starting ELF binaries.
endif
endif

Expand Down
2 changes: 0 additions & 2 deletions binfmt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ include $(TOPDIR)/Make.defs
CSRCS = binfmt_globals.c binfmt_initialize.c binfmt_register.c binfmt_unregister.c
CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c
CSRCS += binfmt_exec.c binfmt_copyargv.c binfmt_copyactions.c binfmt_dumpmodule.c
CSRCS += binfmt_coredump.c

ifeq ($(CONFIG_BINFMT_LOADABLE),y)
CSRCS += binfmt_exit.c
Expand Down Expand Up @@ -58,7 +57,6 @@ endif
# Add configured binary modules

include libnxflat/Make.defs
include libelf/Make.defs

CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)sched

Expand Down
7 changes: 0 additions & 7 deletions binfmt/binfmt_dumpmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ int binfmt_dumpmodule(FAR const struct binary_s *bin)
binfo("Module:\n");
binfo(" entrypt: %p\n", bin->entrypt);
binfo(" mapped: %p size=%zd\n", bin->mapped, bin->mapsize);
binfo(" alloc: %p %p %p\n", bin->alloc[0],
bin->alloc[1],
bin->alloc[2]);
#ifdef CONFIG_BINFMT_CONSTRUCTORS
binfo(" ctors: %p nctors=%d\n", bin->ctors, bin->nctors);
binfo(" dtors: %p ndtors=%d\n", bin->dtors, bin->ndtors);
#endif
#ifdef CONFIG_ARCH_ADDRENV
binfo(" addrenv: %p\n", bin->addrenv);
#endif
Expand Down
8 changes: 4 additions & 4 deletions binfmt/binfmt_execmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@
static void exec_ctors(FAR void *arg)
{
FAR const struct binary_s *binp = (FAR const struct binary_s *)arg;
binfmt_ctor_t *ctor = binp->ctors;
binfmt_ctor_t *ctor = (CODE binfmt_ctor_t *)binp->mod.initarr;
int i;

/* Execute each constructor */

for (i = 0; i < binp->nctors; i++)
for (i = 0; i < binp->mod.ninit; i++)
{
binfo("Calling ctor %d at %p\n", i, ctor);

Expand Down Expand Up @@ -338,7 +338,7 @@ int exec_module(FAR struct binary_s *binp,
* must be the first allocated address space.
*/

tcb->cmn.dspace = binp->alloc[0];
tcb->cmn.dspace = binp->picbase;

/* Re-initialize the task's initial state to account for the new PIC base */

Expand All @@ -362,7 +362,7 @@ int exec_module(FAR struct binary_s *binp,
* until the new task has been started.
*/

if (binp->nctors > 0)
if (binp->mod.ninit > 0)
{
nxtask_starthook(tcb, exec_ctors, binp);
}
Expand Down
1 change: 1 addition & 0 deletions binfmt/binfmt_loadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <debug.h>
#include <errno.h>

#include <nuttx/lib/lib.h>
#include <nuttx/envpath.h>
#include <nuttx/sched.h>
#include <nuttx/kmalloc.h>
Expand Down
Loading
Loading