aboutsummaryrefslogtreecommitdiffstats
path: root/main/libbsd/fix-build-with-musl-on-ppc64le-s390x.patch
blob: 7542f15dc33eb1248fcffd27414ec4984e4e7167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Libbsd includes a.out.h header to get some definitions like struct nlist, struct exec.

In Alpine x86_64 this header is provided by linux-headers package (linux/a.out.h),
in Ubuntu ppc64le it is provided by glibc (a.out.h), but in Alpine ppc64le it is not
available.

A workaround for this problem is to define the types that are being used
by libbsd instead of including the invalid header for ppc64le and s390x.
===
--- libbsd-0.8.3.orig/src/nlist.c
+++ libbsd-0.8.3/src/nlist.c
@@ -40,7 +40,70 @@ static char sccsid[] = "@(#)nlist.c    8.1 (Berkeley) 6/4/93";

 #include <errno.h>
 #include <fcntl.h>
+
+#if defined(__powerpc64__) || defined(__s390x__)
+// Copied from a.out.h, because it is not available on ppc64le with musl
+struct nlist
+{
+  union
+     {
+	char *n_name;
+	struct nlist *n_next;
+	long n_strx;
+     } n_un;
+    unsigned char n_type;
+    char n_other;
+    short n_desc;
+    unsigned long n_value;
+};
+
+struct exec
+{
+  unsigned long a_info; /* Use macros N_MAGIC, etc for access.  */
+  unsigned int a_text;  /* Length of text, in bytes.  */
+  unsigned int a_data;  /* Length of data, in bytes.  */
+  unsigned int a_bss;   /* Length of uninitialized data area for file, in bytes.  */
+  unsigned int a_syms;  /* Length of symbol table data in file, in bytes.  */
+  unsigned int a_entry; /* Start address.  */
+  unsigned int a_trsize;/* Length of relocation info for text, in bytes.  */
+  unsigned int a_drsize;/* Length of relocation info for data, in bytes.  */
+};
+
+#define N_UNDF  0
+#define N_ABS   2
+#define N_TEXT  4
+#define N_DATA  6
+#define N_BSS   8
+#define N_FN    15
+#define N_EXT   1
+#define N_STAB  0340
+
+#define N_MAGIC(exec)	((exec).a_info & 0xffff)
+
+#define OMAGIC 0407
+#define NMAGIC 0410
+#define ZMAGIC 0413
+#define QMAGIC 0314
+#define N_TRSIZE(a)	((a).a_trsize)
+#define N_DRSIZE(a)	((a).a_drsize)
+
+#define N_BADMAG(x) \
+  (N_MAGIC(x) != OMAGIC  && N_MAGIC(x) != NMAGIC \
+  && N_MAGIC(x) != ZMAGIC && N_MAGIC(x) != QMAGIC)
+#define _N_HDROFF(x) (1024 - sizeof (struct exec))
+#define N_TXTOFF(x) \
+  (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \
+  (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
+#define N_DATOFF(x)	(N_TXTOFF(x) + (x).a_text)
+#define N_TRELOFF(x)	(N_DATOFF(x) + (x).a_data)
+#define N_DRELOFF(x)	(N_TRELOFF(x) + N_TRSIZE(x))
+#define N_SYMOFF(x)	(N_DRELOFF(x) + N_DRSIZE(x))
+
+#else
 #include <linux/a.out.h>
+
+#endif
+
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>