]> xenbits.xensource.com Git - people/aperard/mini-os.git/commitdiff
Mini-OS: explicitly mark symbols to be visible for apps
authorJuergen Gross <jgross@suse.com>
Mon, 27 Nov 2023 10:24:53 +0000 (11:24 +0100)
committerJulien Grall <jgrall@amazon.com>
Mon, 4 Dec 2023 16:52:57 +0000 (16:52 +0000)
Add an EXPORT_SYMBOL() macro to explicitly mark a symbol to be visible
for an app or library linked with Mini-OS. This prepares hiding all
other symbols from external components, avoiding any problems with
duplicate symbol names.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
.gitignore
Makefile
include/export.h [new file with mode: 0644]
include/lib.h

index abef46b21cf1d31496f11b83dadeecff21249c35..bacf787e4e29646ddcdce0e5b2049758a7f5a677 100644 (file)
@@ -16,3 +16,4 @@ mini-os.gz
 minios-config.mk
 mini-os-debug
 mini-os-debug.gz
+syms
index 85c6db751a63cae435c2ae230a686de4761fc0c3..588496cb6c84e52c4b01d6f58dfccb4696769a5e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -166,10 +166,11 @@ $(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
        $(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(OBJS) $(LDARCHLIB) -o $@
+       $(OBJCOPY) --dump-section .export_symbol=$(OBJ_DIR)/syms $@
 
 $(OBJ_DIR)/$(TARGET): $(OBJ_DIR)/$(TARGET)-kern.o $(APP_O)
        $(LD) -r $(LDFLAGS) $(OBJ_DIR)/$(TARGET)-kern.o $(APP_O) $(LDLIBS) -o $@.o
-       $(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o
+       $(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start --remove-section=.export_symbol $@.o $@.o
        $(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@-debug
        strip -s $@-debug -o $@
        gzip -n -f -9 -c $@-debug >$@-debug.gz
diff --git a/include/export.h b/include/export.h
new file mode 100644 (file)
index 0000000..7140ac6
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef _EXPORT_H_
+#define _EXPORT_H_
+
+/* Mark a symbol to be visible for apps and libs. */
+#define EXPORT_SYMBOL(sym)          \
+    asm(".section .export_symbol\n" \
+        ".ascii \""#sym"\\n\"\n"    \
+        ".previous\n")
+
+#endif /* _EXPORT_H_ */
index dd68985adf397b4a84b7b698b9dd63e7c1d487dc..abd4e9abead1be6dd86b7962a80ddc26dfccb326 100644 (file)
@@ -53,6 +53,7 @@
 #include <stddef.h>
 #include <xen/xen.h>
 #include <xen/event_channel.h>
+#include <mini-os/export.h>
 #include "gntmap.h"
 
 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)