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

[Xen-changelog] [xen master] x86/livepatch: Fail the build if duplicate symbols exist



commit ece1d5cda17c2815dd194909569deb254ddae575
Author:     Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
AuthorDate: Thu Feb 4 16:40:56 2016 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Wed Oct 30 13:07:25 2019 +0000

    x86/livepatch: Fail the build if duplicate symbols exist
    
    The binary diffing algorithm used by xen-livepatch depends on having unique
    symbols.
    
    The livepatch loading algorithm used by Xen resolves relocations by symbol
    name, and thus also depends on having unique symbols.
    
    Introduce CONFIG_ENFORCE_UNIQUE_SYMBOLS to control failing the build if
    duplicate symbols are found, and disable it in the RANDCONFIG build.
    
    Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
    Release-acked-by: Juergen Gross <jgross@xxxxxxxx>
---
 xen/arch/x86/Makefile              |  1 +
 xen/common/Kconfig                 | 19 +++++++++++++++++--
 xen/tools/kconfig/allrandom.config |  1 +
 xen/tools/symbols.c                | 11 +++++++++--
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 2443fd2cc5..6b369f21cb 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -99,6 +99,7 @@ endif
 
 syms-warn-dup-y := --warn-dup
 syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
+syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup
 
 $(TARGET): TMP = $(@D)/.$(@F).elf32
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index fddb6c1707..f754741972 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -371,9 +371,24 @@ config FAST_SYMBOL_LOOKUP
 
          If unsure, say Y.
 
+config ENFORCE_UNIQUE_SYMBOLS
+       bool "Enforce unique symbols"
+       default y
+       depends on LIVEPATCH
+       ---help---
+         Multiple symbols with the same name aren't generally a problem
+         unless livepatching is to be used.
+
+         Livepatch loading involves resolving relocations against symbol
+         names, and attempting to a duplicate symbol in a livepatch will
+         result in incorrect livepatch application.
+
+         This option should be used to ensure that a build of Xen can have a
+         livepatch build and apply correctly.
+
 config SUPPRESS_DUPLICATE_SYMBOL_WARNINGS
-       bool "Suppress duplicate symbol warnings" if !LIVEPATCH
-       default y if !LIVEPATCH
+       bool "Suppress duplicate symbol warnings" if !ENFORCE_UNIQUE_SYMBOLS
+       default y if !ENFORCE_UNIQUE_SYMBOLS
        ---help---
          Multiple symbols with the same name aren't generally a problem
          unless Live patching is to be used, so these warnings can be
diff --git a/xen/tools/kconfig/allrandom.config 
b/xen/tools/kconfig/allrandom.config
index 76f74320b5..c480896b96 100644
--- a/xen/tools/kconfig/allrandom.config
+++ b/xen/tools/kconfig/allrandom.config
@@ -2,3 +2,4 @@
 
 CONFIG_GCOV_FORMAT_AUTODETECT=y
 CONFIG_UBSAN=n
+CONFIG_ENFORCE_UNIQUE_SYMBOLS=n
diff --git a/xen/tools/symbols.c b/xen/tools/symbols.c
index 05139d1600..9f9e2c9900 100644
--- a/xen/tools/symbols.c
+++ b/xen/tools/symbols.c
@@ -599,7 +599,7 @@ static int compare_name(const void *p1, const void *p2)
 int main(int argc, char **argv)
 {
        unsigned int i;
-       bool unsorted = false, warn_dup = false;
+       bool unsorted = false, warn_dup = false, error_dup = false, found_dup = 
false;
 
        if (argc >= 2) {
                for (i = 1; i < argc; i++) {
@@ -619,6 +619,8 @@ int main(int argc, char **argv)
                                sort_by_name = 1;
                        else if (strcmp(argv[i], "--warn-dup") == 0)
                                warn_dup = true;
+                       else if (strcmp(argv[i], "--error-dup") == 0)
+                               warn_dup = error_dup = true;
                        else if (strcmp(argv[i], "--xensyms") == 0)
                                map_only = true;
                        else
@@ -634,14 +636,19 @@ int main(int argc, char **argv)
                for (i = 1; i < table_cnt; ++i)
                        if (strcmp(SYMBOL_NAME(table + i - 1),
                                   SYMBOL_NAME(table + i)) == 0 &&
-                           table[i - 1].addr != table[i].addr)
+                           table[i - 1].addr != table[i].addr) {
                                fprintf(stderr,
                                        "Duplicate symbol '%s' (%llx != 
%llx)\n",
                                        SYMBOL_NAME(table + i),
                                        table[i].addr, table[i - 1].addr);
+                               found_dup = true;
+                       }
                unsorted = true;
        }
 
+       if (error_dup && found_dup)
+               exit(1);
+
        if (unsorted)
                qsort(table, table_cnt, sizeof(*table), compare_value);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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