[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT PATCH v2 1/3] plat/*: Introduce unikraft internal constructors
Hello Vlad, Please find the review comment inline: Thanks & Regards Sharan On 4/4/19 11:02 PM, Vlad-Andrei BĂDOIU (78692) wrote: From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx> This patch adds a new section for the ukplat_ctortab array. The array is NULL-terminated and consists of function pointers to constructors. The pointers are sorted by priority (0-7) and the array is populated at link time. Libraries can register a constructor function by using the new macro UKPLAT_CTOR_FUNC() (provided with include/uk/plat/ctors.h). This patch was needed because C++ normally uses __attribute__((constructor)) and without this we would run the C++ constructors during the startup with the internal unikraft constructors. This is based on the previous patch of Simon Kuenzer. Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx> --- include/uk/ctors.h | 68 ++++++++++++++++++++++++++++++++++++++ plat/common/x86/link64.lds | 9 +++++ plat/kvm/arm/link64.lds.S | 8 +++++ plat/linuxu/Linker.uk | 2 ++ plat/linuxu/arm/link64.lds | 11 ++++++ plat/linuxu/x86/link64.lds | 6 ++++ plat/xen/arm/link32.lds | 8 +++++ 7 files changed, 112 insertions(+) create mode 100644 include/uk/ctors.h create mode 100644 plat/linuxu/arm/link64.lds create mode 100644 plat/linuxu/x86/link64.lds diff --git a/include/uk/ctors.h b/include/uk/ctors.h new file mode 100644 index 00000000..15ec90fe --- /dev/null +++ b/include/uk/ctors.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Authors: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> + * Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx> + * + * + * Copyright (c) 2019, NEC Europe Ltd., NEC Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY. + */ + +#ifndef __UK_CTORS_H__ +#define __UK_CTORS_H__ + +#include <uk/essentials.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*uk_ctor_func_t)(void); +extern const uk_ctor_func_t uk_ctortab[]; + +/* + * Register a constructor function that is + * called during bootstrap + * @param lvl + * Priority level (0 (higher) to 7 (least)) + * Note: Any other value for level will be ignored + * @param ctorf + * Constructor function to be called + */ +#define UK_CTOR_FUNC(lvl, ctorf) \ + static const uk_ctor_func_t \ + __used __section(".uk_ctortab" #lvl) \ + __uk_ctab ## lvl ## _ ## ctorf = (ctorf) + + +#ifdef __cplusplus +} +#endif + +#endif /* __UK__CTORS_H__ */ diff --git a/plat/common/x86/link64.lds b/plat/common/x86/link64.lds index 018cdac3..a7ba67bb 100644 --- a/plat/common/x86/link64.lds +++ b/plat/common/x86/link64.lds @@ -48,3 +48,12 @@ __eh_frame_hdr_start = .; *(.eh_frame_hdr.*) } __eh_frame_hdr_end = .; + +. = ALIGN(0x1000); +uk_ctortab = .; +.uk_ctortab : +{ + *(SORT_BY_NAME(.uk_ctortab[0-7])) + LONG(0) +} + diff --git a/plat/kvm/arm/link64.lds.S b/plat/kvm/arm/link64.lds.S index 82328633..f0da7768 100644 --- a/plat/kvm/arm/link64.lds.S +++ b/plat/kvm/arm/link64.lds.S @@ -99,6 +99,14 @@ SECTIONS {_erodata = .; + . = ALIGN(__PAGE_SIZE);+ uk_ctortab = .; + .uk_ctortab : + { + *(SORT_BY_NAME(.uk_ctortab[0-7])) + LONG(0) + } + /* Constructor tables (read-only) */ _ctors = .; .preinit_array : { diff --git a/plat/linuxu/Linker.uk b/plat/linuxu/Linker.uk index ef4b201c..a9162a66 100644 --- a/plat/linuxu/Linker.uk +++ b/plat/linuxu/Linker.uk @@ -4,6 +4,8 @@ LINUXU_LDFLAGS-y += -Wl,-e,_liblinuxuplat_start ## Link image ## LINUXU_IMAGE := $(BUILD_DIR)/$(CONFIG_UK_NAME)_linuxu-$(CONFIG_UK_ARCH) +LINUXU_LD_SCRIPT-$(CONFIG_ARCH_X86_64) += $(LIBLINUXUPLAT_BASE)/x86/link64.lds This should not be CONFIG_ARCH_X86_64. Currently we support linuxu on arm32 platform alone. So it should be CONFIG_ARCH_ARM_32. +LINUXU_LD_SCRIPT-$(CONFIG_ARCH_X86_64) += $(LIBLINUXUPLAT_BASE)/arm/link64.lds LINUXU_LD_SCRIPT_FLAGS := $(addprefix -Wl$(comma)-T$(comma),\ $(LINUXU_LD_SCRIPT-y) $(EXTRA_LD_SCRIPT-y))diff --git a/plat/linuxu/arm/link64.lds b/plat/linuxu/arm/link64.ldsnew file mode 100644 index 00000000..2e34b364 --- /dev/null +++ b/plat/linuxu/arm/link64.lds @@ -0,0 +1,11 @@ Rename this file to link.lds. Currently we don't support linuxu platform on ARM64. This file is generic enough across the Arm. + +SECTIONS +{ + . = ALIGN(0x1000); + uk_ctortab = .; + .uk_ctortab : + { + *(SORT_BY_NAME(.uk_ctortab[0-7])) + LONG(0) + } +} +INSERT AFTER .rodata diff --git a/plat/linuxu/x86/link64.lds b/plat/linuxu/x86/link64.lds new file mode 100644 index 00000000..a4d03157 --- /dev/null +++ b/plat/linuxu/x86/link64.lds @@ -0,0 +1,6 @@ +SECTIONS +{ + INCLUDE plat/common/x86/link64.lds +} +INSERT AFTER .rodata + diff --git a/plat/xen/arm/link32.lds b/plat/xen/arm/link32.lds index 2b8e42dd..522df30c 100644 --- a/plat/xen/arm/link32.lds +++ b/plat/xen/arm/link32.lds @@ -78,6 +78,14 @@ SECTIONS . = ALIGN(4096); _erodata = .;+ uk_ctortab = .;+ .uk_ctortab : + { + *(SORT_BY_NAME(.uk_ctortab[0-7])) + LONG(0) + } + . = ALIGN(4096); + _ctors = .; .preinit_array : { . = ALIGN(0x8); _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |