Mini-OS: explicitly mark symbols to be visible for apps
RFC PATCH 1/1 Mini-OS: explicitly mark symbols to be visible for apps
Add an EXPORT_SYMBOL() macro to explicitly mark a symbol to be visible for an app or library linked with Mini-OS. This enables to hide all other symbols from external components, avoiding any problems with duplicate symbol names.
---
Based on top of my previous series "Mini-OS: hide mini-os internal symbols".
This is a RFC as an alternative to the map file containing all visible symbol names. It would add more code churn, but it has the large benefit of declaring visibility of a symbol at the place where it is defined, reducing the chance to miss a proper symbol visibility definition.
This patch is including an example for the do_exit() function in order to prove the viability of the approach.
In case this idea is approved, I'd setup a patch series replacing the second patch of above series with this patch (minus the do_exit() example) and the scattered EXPORT_SYMBOL() instances.
--- Makefile | 3 ++- include/lib.h | 6 ++++++ kernel.c | 1 + mini-os.map | 1 - 4 files changed, 9 insertions(+), 2 deletions(-)
Makefile +2 -1
@@ -166,7 +166,8 @@ $(OBJ_DIR)/arch/x86/minios-x86%.lds: arch/x86/minios-x86.lds.S $(OBJ_DIR)/$(TARGET)-kern.o: $(OBJS) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds mini-os.map $(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) -o $@ - $(OBJCOPY) -w -G $(GLOBAL_PREFIX)* --keep-global-symbols=mini-os.map $@ $@ + $(OBJCOPY) --dump-section .export_symbol=syms mini-os-kern.o + $(OBJCOPY) -w -G $(GLOBAL_PREFIX)* --keep-global-symbols=mini-os.map --keep-global-symbols=syms --remove-section=.export_symbol $@ $@ $(OBJ_DIR)/$(TARGET): $(OBJ_DIR)/$(TARGET)-kern.o $(APP_O) $(LD) -r $(LDFLAGS) $(OBJ_DIR)/$(TARGET)-kern.o $(APP_O) $(LDLIBS) -o [email protected]
include/lib.h +6 -0
@@ -64,6 +64,12 @@#define BUILD_BUG_ON (cond) ((void)BUILD_BUG_ON_ZERO(cond))#endif +#define EXPORT_SYMBOL (sym) \ + extern typeof(sym) sym; \ + asm(".section \".export_symbol\",\"a\"\n" \ + "\t.ascii \""#sym"\n\"\n" \ + ".previous") +#ifdef HAVE_LIBC #include <sys/queue.h> #include <sys/stat.h>
kernel.c +1 -0
@@ -199,3 +199,4 @@ void do_exit(void)HYPERVISOR_sched_op (SCHEDOP_shutdown, &sched_shutdown); } } +EXPORT_SYMBOL (do_exit);
mini-os.map +0 -1
@@ -69,7 +69,6 @@ close closedir closelog connect -do_exit dup dup2 err
Signature · 1 line
2.35.3
Juergen Gross, le ven. 24 nov. 2023 14:59:03 +0100, a ecrit:
Quoted 6 lines
Add an
EXPORT_SYMBOL()macro to explicitly mark a symbol to be visible for an app or library linked with Mini-OS. This enables to hide all other symbols from external components, avoiding any problems with duplicate symbol names.Signed-off-by Juergen Gross <[email protected]>
Quoted 5 lines
---
Based on top of my previous series "Mini-OS: hide mini-os internal symbols".
This is a RFC as an alternative to the map file containing all visible symbol names. It would add more code churn, but it has the
Quoted 8 lines
large benefit of declaring visibility of a symbol at the place where it is defined, reducing the chance to miss a proper symbol visibility definition.
This patch is including an example for thedo_exit()function in order to prove the viability of the approach.
In case this idea is approved, I'd setup a patch series replacing the second patch of above series with this patch (minus thedo_exit()example) and the scatteredEXPORT_SYMBOL()instances.
I agree on the rationale, indeed.
Quoted 63 lines
Signed-off-by Juergen Gross <[email protected]>--- Makefile | 3 ++- include/lib.h | 6 ++++++ kernel.c | 1 + mini-os.map | 1 - 4 files changed, 9 insertions(+), 2 deletions(-)Makefile +2
-1@@ -166,7 +166,8 @@ $(OBJ_DIR)/arch/x86/minios-x86%.lds: arch/x86/minios-x86.lds.S $(OBJ_DIR)/$(TARGET)-kern.o: $(OBJS) arch_lib $(OBJ_DIR)/$(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds mini-os.map $(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) -o $@ - $(OBJCOPY) -w -G $(GLOBAL_PREFIX)* --keep-global-symbols=mini-os.map $@ $@ + $(OBJCOPY) --dump-section .export_symbol=syms mini-os-kern.o + $(OBJCOPY) -w -G $(GLOBAL_PREFIX)* --keep-global-symbols=mini-os.map --keep-global-symbols=syms --remove-section=.export_symbol $@ $@ $(OBJ_DIR)/$(TARGET): $(OBJ_DIR)/$(TARGET)-kern.o $(APP_O) $(LD) -r $(LDFLAGS) $(OBJ_DIR)/$(TARGET)-kern.o $(APP_O) $(LDLIBS) -o [email protected]include/lib.h +6
-0@@ -64,6 +64,12 @@#define BUILD_BUG_ON (cond) ((void)BUILD_BUG_ON_ZERO(cond))#endif +#define EXPORT_SYMBOL (sym) \ + extern typeof(sym) sym; \ + asm(".section \".export_symbol\",\"a\"\n" \ + "\t.ascii \""#sym"\n\"\n" \ + ".previous") +#ifdef HAVE_LIBC #include <sys/queue.h> #include <sys/stat.h> kernel.c +1
-0@@ -199,3 +199,4 @@ void do_exit(void)HYPERVISOR_sched_op (SCHEDOP_shutdown, &sched_shutdown); } } +EXPORT_SYMBOL (do_exit);mini-os.map +0
-1@@ -69,7 +69,6 @@ close closedir closelog connect -do_exit dup dup2 errSignature · 1 line
2.35.3
Signature · 4 lines
Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.