[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 01/11] build: resolve common symbols in each lib individually



If a symbol is not initialized, gcc declares it as a weak. It will be
resolved during the linking time.

Common symbols inside a library are fine, but we don't want them to be
resolved together with common symbols from another library.

For example:
lib/foo/main.c:
   int some_variable;
   int main(void) {
      printf("libfoo: %p\n", some_variable);
   }
lib/bar/main.c:
   char some_variable;
   int main(void) {
      printf("libbar: %p\n", some_variable);
   }

After linking the final Unikraft image, both libfoo and libbar will
get one address for their some_variable. Even if neither of them was
never declared "extern". Even if they have different types. Even if
some_variable is not listed in exportsyms.uk

The solution is to link library object files (libname.ld.o) with
'-d'. This will force linker to do allocation for common symbols.

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
Reviewed-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
 Makefile.uk             | 2 +-
 lib/ukbus/exportsyms.uk | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile.uk b/Makefile.uk
index 0cc66907..289305ae 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -20,7 +20,7 @@ CXXINCLUDES += -nostdinc -nostdlib -I$(CONFIG_UK_BASE)/include
 # Set the text and data sections to be readable and writable. Also,
 # do not page-align the data segment. If the output format supports
 # Unix style magic numbers, mark the output as OMAGIC.
-LIBLDFLAGS  += -nostdinc -nostdlib -Wl,--omagic -Wl,-r
+LIBLDFLAGS  += -nostdinc -nostdlib -Wl,--omagic -Wl,-r -Wl,-d
 LDFLAGS     += -nostdinc -nostdlib -Wl,--omagic -Wl,--build-id=none
 
 CFLAGS-$(CONFIG_OPTIMIZE_NONE)            += -O0 -fno-optimize-sibling-calls 
-fno-tree-vectorize
diff --git a/lib/ukbus/exportsyms.uk b/lib/ukbus/exportsyms.uk
index db4476df..b2023578 100644
--- a/lib/ukbus/exportsyms.uk
+++ b/lib/ukbus/exportsyms.uk
@@ -3,3 +3,4 @@ uk_bus_init
 uk_bus_probe
 _uk_bus_register
 _uk_bus_unregister
+uk_bus_list
-- 
2.19.2


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.