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

modlib: preprocess gnu-elf.ld for executable ELF #15444

Merged
merged 4 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion arch/arm/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ ifeq ($(CONFIG_PIC),y)
# Generate an executable elf, need to ignore undefined symbols
LDELFFLAGS += --unresolved-symbols=ignore-in-object-files --emit-relocs
else
LDELFFLAGS += -r
ifneq ($(CONFIG_BINFMT_ELF_EXECUTABLE),y)
LDELFFLAGS += -r
endif
endif

LDELFFLAGS += -e main -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)
Expand Down
1 change: 1 addition & 0 deletions arch/arm/src/qemu/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ config ARCH_CHIP_QEMU_CORTEXA7
bool "Qemu virtual Processor (cortex-a7)"
select ARCH_CORTEXA7
select ARCH_HAVE_ADDRENV
select ARCH_HAVE_ELF_EXECUTABLE
select ARCH_HAVE_LOWVECTORS
select ARCH_HAVE_MULTICPU
select ARCH_NEED_ADDRENV_MAPPING
Expand Down
9 changes: 7 additions & 2 deletions include/nuttx/addrenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <nuttx/config.h>

#ifndef __ASSEMBLY__

#ifdef CONFIG_BUILD_KERNEL
# include <signal.h>
#endif
Expand All @@ -40,6 +42,8 @@

#include <arch/arch.h>

#endif /* __ASSEMBLY__ */

#ifdef CONFIG_ARCH_ADDRENV

/****************************************************************************
Expand Down Expand Up @@ -241,6 +245,9 @@
(CONFIG_ARCH_PGPOOL_VBASE + CONFIG_ARCH_PGPOOL_SIZE)

#endif

#ifndef __ASSEMBLY__

/****************************************************************************
* Public Type Definitions
****************************************************************************/
Expand All @@ -251,8 +258,6 @@ struct tcb_s; /* Forward reference to TCB */
* Public Types
****************************************************************************/

#ifndef __ASSEMBLY__

struct addrenv_s
{
struct arch_addrenv_s addrenv; /* The address environment page directory */
Expand Down
1 change: 1 addition & 0 deletions libs/libc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/exec_symtab.c
/modlib_symtab.c
modlib/gnu-elf.ld
6 changes: 6 additions & 0 deletions libs/libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ context:: bin kbin
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo context BIN=$(BIN)
endif
ifeq ($(CONFIG_LIBC_MODLIB),y)
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
$(Q) $(MAKE) -C modlib context
endif


# Dependencies

Expand Down Expand Up @@ -210,6 +214,7 @@ depend:: .depend

clean::
$(Q) $(MAKE) -C zoneinfo clean BIN=$(BIN)
$(Q) $(MAKE) -C modlib clean
$(call DELFILE, $(BIN))
$(call DELFILE, $(KBIN))
$(call CLEAN)
Expand All @@ -218,6 +223,7 @@ clean::

distclean:: clean
$(Q) $(MAKE) -C zoneinfo distclean BIN=$(BIN)
$(Q) $(MAKE) -C modlib distclean
$(call DELFILE, exec_symtab.c)
$(call DELFILE, .depend)
$(call DELDIR, bin)
Expand Down
40 changes: 40 additions & 0 deletions libs/libc/modlib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
############################################################################
# libs/libc/modlib/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# 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.
#
############################################################################

include $(TOPDIR)/Make.defs

# Generate gnu-elf.ld from gnu-elf.ld.in

gnu-elf.ld: gnu-elf.ld.in
$(call PREPROCESS, $<, $@)

# Create initial context

context: gnu-elf.ld

.PHONY: context clean distclean

clean:
$(call CLEAN)

distclean: clean
$(call DELFILE, gnu-elf.ld)
20 changes: 17 additions & 3 deletions libs/libc/modlib/gnu-elf.ld → libs/libc/modlib/gnu-elf.ld.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* libs/libc/modlib/gnu-elf.ld
* libs/libc/modlib/gnu-elf.ld.in
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand All @@ -18,9 +18,23 @@
*
****************************************************************************/


#include <nuttx/config.h>

#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_BINFMT_ELF_EXECUTABLE)
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
# define __ASSEMBLY__
# include <nuttx/addrenv.h>

# define TEXT CONFIG_ARCH_TEXT_VBASE
# define DATA CONFIG_ARCH_DATA_VBASE + ARCH_DATA_RESERVE_SIZE
#else
# define TEXT 0x0
# define DATA
#endif

SECTIONS
{
.text 0x00000000 :
.text TEXT :
{
_stext = . ;
*(.text)
Expand Down Expand Up @@ -58,7 +72,7 @@ SECTIONS
_erodata = . ;
}

.data :
.data DATA :
{
_sdata = . ;
*(.data)
Expand Down
Loading