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

Re: [Minios-devel] [UNIKRAFT PATCH 2/2] lib/ukboot: move weak main in separate sub-lib



Hello Yuri,

I agree with the solution.

Maybe it is wise to add an "EXPERIMENTAL" tag around the LTO Config.uk option.

Thanks & Regards
Sharan

On 1/4/19 5:18 PM, Yuri Volchkov wrote:
Link Time Optimization does not work well with incremental linking (ld
-r), which is heavily used by Unikraft.

The ukboot has a weak main() function, which is supposed to be called
if no other library/application provided a proper main. However gcc
resolves main() to whatever is available while linking the
libukboot.ld.o. Which is the weak one.

In the upcoming gcc v9 release a better support of incremental link
optimization is announced. Which hopefully will fix this issue. But
for now, let's fix it with a workaround.

Let's create a sublib under the ukboot, containing only the weak
main. This way we will leave no chance for the first "ld -r" to link
with the wrong main. The next "ld -r" will have all the objects, so it
will be able to make correct decision.

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
  lib/ukboot/Makefile.uk | 12 ++++++++++++
  lib/ukboot/boot.c      |  7 -------
  lib/ukboot/weak_main.c |  9 +++++++++
  3 files changed, 21 insertions(+), 7 deletions(-)
  create mode 100644 lib/ukboot/weak_main.c

diff --git a/lib/ukboot/Makefile.uk b/lib/ukboot/Makefile.uk
index 2b7f69f..55f205d 100644
--- a/lib/ukboot/Makefile.uk
+++ b/lib/ukboot/Makefile.uk
@@ -4,3 +4,15 @@ CINCLUDES-$(CONFIG_LIBUKBOOT)          += 
-I$(LIBUKBOOT_BASE)/include
  CXXINCLUDES-$(CONFIG_LIBUKBOOT)       += -I$(LIBUKBOOT_BASE)/include
LIBUKBOOT_SRCS-y += $(LIBUKBOOT_BASE)/boot.c
+
+# The main() is in the separate library to fool the LTO. Which is
+# trying to resolve the main() function call to whatever is available
+# during liking the library object file. And this will be the weak
+# main. So even if the proper main() is provided later, the weak one
+# will be called, because the decision is already made.
+#
+# This does not sound right, but LTO does not work well with
+# incremental linking (ld -r). This possibly will be fixed in gcc
+# v9. But we have to deal with it now.
+$(eval $(call addlib_s,libukboot_main,$(CONFIG_LIBUKBOOT)))
+LIBUKBOOT_MAIN_SRCS-y += $(LIBUKBOOT_BASE)/weak_main.c
diff --git a/lib/ukboot/boot.c b/lib/ukboot/boot.c
index 174dd5b..4846782 100644
--- a/lib/ukboot/boot.c
+++ b/lib/ukboot/boot.c
@@ -266,10 +266,3 @@ void ukplat_entry(int argc, char *argv[])
        main_thread_func(&tma);
  #endif
  }
-
-/* Internal main */
-int main(int argc __unused, char *argv[] __unused)
-{
-       printf("weak main() called. Symbol was not replaced!\n");
-       return -EINVAL;
-}
diff --git a/lib/ukboot/weak_main.c b/lib/ukboot/weak_main.c
new file mode 100644
index 0000000..697720c
--- /dev/null
+++ b/lib/ukboot/weak_main.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include <errno.h>
+
+/* Internal main */
+int __weak main(int argc __unused, char *argv[] __unused)
+{
+       printf("weak main() called. Symbol was not replaced!\n");
+       return -EINVAL;
+}


_______________________________________________
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®.