From 657247bda89d60112d79bb9b8d223eca5f9641b5 Mon Sep 17 00:00:00 2001 From: Yanfeng Liu Date: Thu, 9 Jan 2025 08:11:45 +0800 Subject: [PATCH] libc/modlib: preprocess gnu-elf.ld This generates gnu-elf.ld via preprocessing of gnu-elf.ld.in so that to reduce board specific app linker scripts in kernel mode when BINFMT_ELF_EXECUTABLE is enabled. Signed-off-by: Yanfeng Liu --- libs/libc/.gitignore | 1 + libs/libc/Makefile | 6 +++ libs/libc/modlib/Makefile | 40 +++++++++++++++++++ .../libc/modlib/{gnu-elf.ld => gnu-elf.ld.in} | 20 ++++++++-- 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 libs/libc/modlib/Makefile rename libs/libc/modlib/{gnu-elf.ld => gnu-elf.ld.in} (86%) diff --git a/libs/libc/.gitignore b/libs/libc/.gitignore index 2f99ba5919..216ebb0947 100644 --- a/libs/libc/.gitignore +++ b/libs/libc/.gitignore @@ -1,2 +1,3 @@ /exec_symtab.c /modlib_symtab.c +modlib/gnu-elf.ld diff --git a/libs/libc/Makefile b/libs/libc/Makefile index fb0f2d79f1..2cc26625b8 100644 --- a/libs/libc/Makefile +++ b/libs/libc/Makefile @@ -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) + $(Q) $(MAKE) -C modlib context +endif + # Dependencies @@ -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) @@ -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) diff --git a/libs/libc/modlib/Makefile b/libs/libc/modlib/Makefile new file mode 100644 index 0000000000..2d98a157e3 --- /dev/null +++ b/libs/libc/modlib/Makefile @@ -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) diff --git a/libs/libc/modlib/gnu-elf.ld b/libs/libc/modlib/gnu-elf.ld.in similarity index 86% rename from libs/libc/modlib/gnu-elf.ld rename to libs/libc/modlib/gnu-elf.ld.in index bd5733f335..d0fb28cf30 100644 --- a/libs/libc/modlib/gnu-elf.ld +++ b/libs/libc/modlib/gnu-elf.ld.in @@ -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 @@ -18,9 +18,23 @@ * ****************************************************************************/ + +#include + +#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_BINFMT_ELF_EXECUTABLE) +# define __ASSEMBLY__ +# include + +# 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) @@ -58,7 +72,7 @@ SECTIONS _erodata = . ; } - .data : + .data DATA : { _sdata = . ; *(.data)