xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH LP-BUILD-TOOLS] Allow patching files compiled multiple times
@ 2018-02-23 17:08 Ross Lagerwall
  2018-03-05 10:32 ` Ross Lagerwall
  0 siblings, 1 reply; 3+ messages in thread
From: Ross Lagerwall @ 2018-02-23 17:08 UTC (permalink / raw)
  To: xen-devel; +Cc: Ross Lagerwall

gas prior to binutils commit fbdf9406b0 (appears in 2.27) outputs symbol
table entries resulting from .file in reverse order. If we get two
consecutive file symbols, prefer the first one if that names an object
file or has a directory component (to cover multiply compiled files).

This is the same workaround that was applied in Xen commit d37d63d4b548
("symbols: prefix static symbols with their source file names") for
Xen's internal symbol table.

This fixes building a livepatch for XSA-243.
---
 lookup.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lookup.c b/lookup.c
index 39125c6..645b91a 100644
--- a/lookup.c
+++ b/lookup.c
@@ -149,16 +149,34 @@ int lookup_local_symbol(struct lookup_table *table, char *name, char *hint,
 	struct symbol *sym, *match = NULL;
 	int i;
 	char *curfile = NULL;
+	enum { other, multi_source } last_type = other;
 
 	memset(result, 0, sizeof(*result));
 	for_each_symbol(i, sym, table) {
 		if (sym->type == STT_FILE) {
+			const char *ext = strrchr(sym->name, '.');
+			int multi = strchr(sym->name, '/') ||
+				    (ext && ext[1] == 'o');
+
+			/*
+			 * gas prior to binutils commit fbdf9406b0 (appears in
+			 * 2.27) outputs symbol table entries resulting from
+			 * .file in reverse order. If we get two consecutive
+			 * file symbols, prefer the first one if that names an
+			 * object file or has a directory component (to cover
+			 * multiply compiled files).
+			 */
+			if (last_type == multi_source)
+				continue;
+
 			if (!strcmp(sym->name, hint)) {
 				curfile = sym->name;
+				last_type = multi ? multi_source : other;
 				continue; /* begin hint file symbols */
 			} else if (curfile)
 				curfile = NULL; /* end hint file symbols */
 		}
+		last_type = other;
 		if (!curfile)
 			continue;
 		if (sym->bind == STB_LOCAL && !strcmp(sym->name, name)) {
-- 
2.9.5


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-05 20:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-23 17:08 [PATCH LP-BUILD-TOOLS] Allow patching files compiled multiple times Ross Lagerwall
2018-03-05 10:32 ` Ross Lagerwall
2018-03-05 20:01   ` Konrad Rzeszutek Wilk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).