summaryrefslogtreecommitdiffstats
path: root/meta/recipes-bsp/efivar/efivar/0005-Revamp-efi_well_known_-variable-handling.patch
blob: 758a151138609e9ea78eb0c2a7c1cb4a96e6eb7a (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
From 8c20b2242925616dfccc97b9be29f36afcf8034d Mon Sep 17 00:00:00 2001
From: Nicholas Vinson <nvinson234@gmail.com>
Date: Mon, 10 Oct 2022 14:22:36 -0400
Subject: [PATCH] Revamp efi_well_known_* variable handling

The current implementation attempts to use the linker to create aliases
for efi_well_known_guids and efi_well_known_names. It also tries to use
the linker to generate the variables efi_well_known_guids_end and
efi_well_known_names_end.

When building with clang, the generated linker result results in a
broken libefivar.so that causes programs to segfault when linked against
it.  This change does away with linker script hacker and instead
introduces pointers to store the locations of efi_well_known_guids_end
and efi_well_known_names_end.

Additionally, efi_well_known_guids and efi_well_known_names are now
created as pointers that point to the beginning of their respective
arrays.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Fixes: #234
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
Upstream-Status: Backport [https://github.com/rhboot/efivar/commit/cfd686de51494d3e34be896a91835657ccab37d4]

 src/Makefile               |  7 ++--
 src/include/rules.mk       |  5 +--
 src/include/workarounds.mk | 24 -------------
 src/makeguids.c            | 72 +++++++++++++-------------------------
 4 files changed, 27 insertions(+), 81 deletions(-)
 delete mode 100644 src/include/workarounds.mk

diff --git a/src/Makefile b/src/Makefile
index b10051b..c69caf4 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,7 +4,6 @@ include $(TOPDIR)/src/include/deprecated.mk
 include $(TOPDIR)/src/include/version.mk
 include $(TOPDIR)/src/include/rules.mk
 include $(TOPDIR)/src/include/defaults.mk
-include $(TOPDIR)/src/include/workarounds.mk
 
 LIBTARGETS=libefivar.so libefiboot.so libefisec.so
 STATICLIBTARGETS=libefivar.a libefiboot.a libefisec.a
@@ -30,7 +29,7 @@ EFISECDB_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(EFISECDB_SOURCES)))
 GENERATED_SOURCES = include/efivar/efivar-guids.h guid-symbols.c
 MAKEGUIDS_SOURCES = makeguids.c util-makeguids.c
 MAKEGUIDS_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(MAKEGUIDS_SOURCES)))
-MAKEGUIDS_OUTPUT = $(GENERATED_SOURCES) guids.lds
+MAKEGUIDS_OUTPUT = $(GENERATED_SOURCES)
 
 util-makeguids.c :
 	cp util.c util-makeguids.c
@@ -84,7 +83,7 @@ $(MAKEGUIDS_OUTPUT) : guids.txt
 	if [ "$${missing}" != "no" ]; then \
 		exit 1 ; \
 	fi
-	./makeguids $(LD_DASH_T) guids.txt guid-symbols.c include/efivar/efivar-guids.h guids.lds
+	./makeguids guids.txt guid-symbols.c include/efivar/efivar-guids.h
 
 prep : makeguids $(GENERATED_SOURCES)
 
@@ -96,7 +95,6 @@ libefivar.a : $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS))
 libefivar.so : $(LIBEFIVAR_OBJECTS)
 libefivar.so : | $(GENERATED_SOURCES) libefivar.map
 libefivar.so : LIBS=dl
-libefivar.so : LDSCRIPTS=guids.lds
 libefivar.so : MAP=libefivar.map
 
 efivar : $(EFIVAR_OBJECTS) | libefivar.so
@@ -137,7 +135,6 @@ deps : $(ALL_SOURCES)
 clean : 
 	@rm -rfv *~ *.o *.a *.E *.so *.so.* *.pc *.bin .*.d *.map \
 		makeguids guid-symbols.c include/efivar/efivar-guids.h \
-		guids.lds \
 		$(TARGETS) $(STATICTARGETS)
 	@# remove the deps files we used to create, as well.
 	@rm -rfv .*.P .*.h.P *.S.P include/efivar/.*.h.P
diff --git a/src/include/rules.mk b/src/include/rules.mk
index f309f86..8d0b68a 100644
--- a/src/include/rules.mk
+++ b/src/include/rules.mk
@@ -3,7 +3,6 @@ default : all
 .PHONY: default all clean install test
 
 include $(TOPDIR)/src/include/version.mk
-include $(TOPDIR)/src/include/workarounds.mk
 
 comma:= ,
 empty:=
@@ -36,9 +35,7 @@ family = $(foreach FAMILY_SUFFIX,$(FAMILY_SUFFIXES),$($(1)_$(FAMILY_SUFFIX)))
 	$(CCLD) $(CCLDFLAGS) $(CPPFLAGS) -o $@ $(sort $^) $(LDLIBS)
 
 %.so :
-	$(CCLD) $(CCLDFLAGS) $(CPPFLAGS) $(SOFLAGS) \
-		$(foreach LDS,$(LDSCRIPTS),$(LD_DASH_T) $(LDS)) \
-		-o $@ $^ $(LDLIBS)
+	$(CCLD) $(CCLDFLAGS) $(CPPFLAGS) $(SOFLAGS) -o $@ $^ $(LDLIBS)
 	ln -vfs $@ $@.1
 
 %.abixml : %.so
diff --git a/src/include/workarounds.mk b/src/include/workarounds.mk
deleted file mode 100644
index 57394ed..0000000
--- a/src/include/workarounds.mk
+++ /dev/null
@@ -1,24 +0,0 @@
-# SPDX-License-Identifier: SPDX-License-Identifier: LGPL-2.1-or-later
-#
-# workarounds.mk - workarounds for weird stuff behavior
-
-LD_FLAVOR := $(shell LC_ALL=C $(LD) --version | grep -E '^((.* )?LLD|GNU ld)'|sed 's/.* LLD/LLD/;s/ .*//g')
-LD_VERSION := $(shell LC_ALL=C $(LD) --version | grep -E '^((.* )?LLD|GNU ld)'|sed 's/.* LLD/LLD/;s/.* //')
-# 2.35 is definitely broken and 2.36 seems to work
-LD_DASH_T := $(shell \
-	if [ "x${LD_FLAVOR}" = xLLD ] ; then \
-		echo "" ; \
-	elif [ "x${LD_FLAVOR}" = xGNU ] ; then \
-		if echo "${LD_VERSION}" | grep -q -E '^2\.3[6789]|^2\.[456789]|^[3456789]|^[[:digit:]][[:digit:]]' ; then \
-			echo '-T' ; \
-		else \
-			echo "" ; \
-		fi ; \
-	else \
-		echo "Your linker ${LD_FLAVOR} version ${LD_VERSION} is not supported" ; \
-		exit 1 ; \
-	fi)
-
-export LD_DASH_T
-
-# vim:ft=make
diff --git a/src/makeguids.c b/src/makeguids.c
index e4ff411..b9e9312 100644
--- a/src/makeguids.c
+++ b/src/makeguids.c
@@ -107,51 +107,46 @@ write_guidnames(FILE *out, const char *listname,
 			gn->symbol, gn->name, gn->description);
 	}
 	fprintf(out, "};\n");
+        fprintf(out, "const struct efivar_guidname\n"
+			"\t__attribute__((__visibility__ (\"default\")))\n"
+			"\t* const %s = %s_;\n", listname, listname);
+        fprintf(out, "const struct efivar_guidname\n"
+			"\t__attribute__((__visibility__ (\"default\")))\n"
+                        "\t* const %s_end = %s_\n\t+ %zd;\n",
+                        listname, listname, n - 1);
 }
 
 int
 main(int argc, char *argv[])
 {
 	int rc;
-	int argstart = 0;
-	FILE *symout, *header, *ldsout;
-	int dash_t = 0;
+	FILE *symout, *header;
 
-	if (argc < 5) {
+	if (argc < 4) {
 		errx(1, "Not enough arguments.\n");
-	} else if (argc > 5 && !strcmp(argv[1],"-T")) {
-		argstart = 1;
-		dash_t = 1;
-	} else if (argc > 5) {
+	} else if (argc > 4) {
 		errx(1, "Too many arguments.\n");
 	}
 
-	symout = fopen(argv[argstart + 2], "w");
+	symout = fopen(argv[2], "w");
 	if (symout == NULL)
-		err(1, "could not open \"%s\"", argv[argstart + 2]);
-	rc = chmod(argv[argstart + 2], 0644);
+		err(1, "could not open \"%s\"", argv[2]);
+	rc = chmod(argv[2], 0644);
 	if (rc < 0)
-		warn("chmod(%s, 0644)", argv[argstart + 2]);
+		warn("chmod(%s, 0644)", argv[2]);
 
-	header = fopen(argv[argstart + 3], "w");
+	header = fopen(argv[3], "w");
 	if (header == NULL)
-		err(1, "could not open \"%s\"", argv[argstart + 3]);
-	rc = chmod(argv[argstart + 3], 0644);
-	if (rc < 0)
-		warn("chmod(%s, 0644)", argv[argstart + 3]);
-
-	ldsout = fopen(argv[argstart + 4], "w");
-	if (ldsout == NULL)
-		err(1, "could not open \"%s\"", argv[argstart + 4]);
-	rc = chmod(argv[argstart + 4], 0644);
+		err(1, "could not open \"%s\"", argv[3]);
+	rc = chmod(argv[3], 0644);
 	if (rc < 0)
-		warn("chmod(%s, 0644)", argv[argstart + 4]);
+		warn("chmod(%s, 0644)", argv[3]);
 
 	struct guidname_index *guidnames = NULL;
 
-	rc = read_guids_at(AT_FDCWD, argv[argstart + 1], &guidnames);
+	rc = read_guids_at(AT_FDCWD, argv[1], &guidnames);
 	if (rc < 0)
-		err(1, "could not read \"%s\"", argv[argstart + 1]);
+		err(1, "could not read \"%s\"", argv[1]);
 
 	struct efivar_guidname *outbuf;
 
@@ -239,12 +234,11 @@ struct efivar_guidname {\n\
 	fprintf(header,
 		"extern const struct efivar_guidname\n"
 			"\t__attribute__((__visibility__ (\"default\")))\n"
-			"\tefi_well_known_guids[%d];\n",
-		i);
+			"\t* const efi_well_known_guids;\n");
 	fprintf(header,
 		"extern const struct efivar_guidname\n"
 			"\t__attribute__((__visibility__ (\"default\")))\n"
-			"\tefi_well_known_guids_end;\n");
+			"\t* const efi_well_known_guids_end;\n");
 	fprintf(header,
 		"extern const uint64_t\n"
 			"\t__attribute__((__visibility__ (\"default\")))\n"
@@ -252,12 +246,11 @@ struct efivar_guidname {\n\
 	fprintf(header,
 		"extern const struct efivar_guidname\n"
 			"\t__attribute__((__visibility__ (\"default\")))\n"
-			"\tefi_well_known_names[%d];\n",
-		i);
+			"\t* const efi_well_known_names;\n");
 	fprintf(header,
 		"extern const struct efivar_guidname\n"
 			"\t__attribute__((__visibility__ (\"default\")))\n"
-			"\tefi_well_known_names_end;\n");
+			"\t* const efi_well_known_names_end;\n");
 	fprintf(header,
 		"extern const uint64_t\n"
 			"\t__attribute__((__visibility__ (\"default\")))\n"
@@ -302,23 +295,6 @@ struct efivar_guidname {\n\
 
 	fclose(symout);
 
-	fprintf(ldsout,
-		"SECTIONS\n"
-		"{\n"
-		"  .data :\n"
-		"  {\n"
-		"    efi_well_known_guids = efi_well_known_guids_;\n"
-		"    efi_well_known_guids_end = efi_well_known_guids_ + %zd;\n"
-		"    efi_well_known_names = efi_well_known_names_;\n"
-		"    efi_well_known_names_end = efi_well_known_names_ + %zd;\n"
-		"  }\n"
-		"}%s;\n",
-		(line - 1) * sizeof(struct efivar_guidname),
-		(line - 1) * sizeof(struct efivar_guidname),
-		dash_t ? " INSERT AFTER .data" : "");
-
-	fclose(ldsout);
-
 	free(guidnames->strtab);
 	free(guidnames);