[libvirt] [PATCH] util: fix build error on non-Linux systems

Laine Stump laine at laine.org
Fri Jun 28 08:12:06 UTC 2013


Building on FreeBSD had this linker error:

/work/a/ports/devel/libvirt/work/libvirt-1.1.0/src/.libs/libvirt.so:
   undefined reference to `virPCIDeviceAddressParse'

This was caused by the new use of virPCIDeviceAddressParse in a
portion of virpci.c that wasn't linux-only (in commit 72c029d8). The
problem was that virPCIDeviceAddressParse had originally been defined
inside #ifdef _linux (because it was only used by another function
that was inside the same ifdef).

The solution is to move it out to the part of virpci.c that is
compiled on all platforms.

(Because the portion that was "moved" was 40-50 lines, but only moved
up by 15 lines, the diff for the patch is less than non-informative -
rather than showing that part that I moved, it shows the bit that was
previously before the moved part, and now sits *after* it.)
---
Pushed under the build-breaker rule.

I actually hadn't noticed that some of the functions in virpci.c were
Linux-only. It looks like this was done because those functions use
the Linux sysfs to get information about the devices. However, much of
the rest of virpci.c does the same thing, so we should probably
revisit which of the functions in that file are compiled only on Linux
and which are compile for everyone.

 src/util/virpci.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index 0ed29e7..7d83bdb 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -2261,21 +2261,6 @@ int virPCIDeviceIsAssignable(virPCIDevicePtr dev,
     return 1;
 }
 
-#ifdef __linux__
-
-/*
- * returns true if equal
- */
-static bool
-virPCIDeviceAddressIsEqual(virPCIDeviceAddressPtr bdf1,
-                           virPCIDeviceAddressPtr bdf2)
-{
-    return ((bdf1->domain == bdf2->domain) &&
-            (bdf1->bus == bdf2->bus) &&
-            (bdf1->slot == bdf2->slot) &&
-            (bdf1->function == bdf2->function));
-}
-
 static int
 logStrToLong_ui(char const *s,
                 char **end_ptr,
@@ -2327,6 +2312,21 @@ out:
     return ret;
 }
 
+#ifdef __linux__
+
+/*
+ * returns true if equal
+ */
+static bool
+virPCIDeviceAddressIsEqual(virPCIDeviceAddressPtr bdf1,
+                           virPCIDeviceAddressPtr bdf2)
+{
+    return ((bdf1->domain == bdf2->domain) &&
+            (bdf1->bus == bdf2->bus) &&
+            (bdf1->slot == bdf2->slot) &&
+            (bdf1->function == bdf2->function));
+}
+
 static int
 virPCIGetDeviceAddressFromSysfsLink(const char *device_link,
                                     virPCIDeviceAddressPtr *bdf)
-- 
1.7.11.7




More information about the libvir-list mailing list