Skip to contentSkip to conversation

symbols: explicitly specify source file name for symtab

PATCH In review Jan Beulich 4 participants 6 messages May 11 – May 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 symbols: explicitly specify source file name for symtab

If there are any local symbols in an object file, GNU ld will create an STT_FILE symbol derived from the object file name if there is none in the incoming symbol table. The object file name, however, varies between linking passes. As a result, symbol name compression can yield different results if any of those local symbols need retaining (Arm [and RISC-V] mapping symbols are omitted, for example). If that difference in compression would yield a difference in the sizes of symbol_names[] or symbols_token_table[], the compare-symbol-tables sanity check will fail.

Fixes d37d63d4b548 ("symbols: prefix static symbols with their source file names")

---
The observed problem was with a stub generated as Arm64 erratum 843419 workaround. Such stubs' symbols (imo wrongly) are associated with the last input object, rather than the input object they belong to. Also for other kinds of stubs, afaict. See
https://sourceware.org/bugzilla/show_bug.cgi?id=34140.

As per the above, having a Fixes: tag here is questionable.

xen/arch/x86/Makefile +4 -1
@@ -200,7 +200,8 @@ $(TARGET).efi: $(objtree)/prelink.o $(no
 ifeq ($(CONFIG_DEBUG_INFO),y)
 	$(if $(filter --strip-debug,$(EFI_LDFLAGS)),echo,:) "Will strip debug info from $(@F)"
 endif
-	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0s.S
+	$(objtree)/tools/symbols $(all_symbols) --source-name=$(@F).S --empty \
+		> $(dot-target).0s.S
 	$(MAKE) $(build)=$(@D) .$(@F).0s.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
 	          $(LD) $(call EFI_LDFLAGS,$(base)) -T $(obj)/efi.lds $< $(relocs-dummy) \
@@ -210,6 +211,7 @@ endif
 		> $(dot-target).1r.S
 	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).0 \
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+                  --source-name=$(@F).S \
 		> $(dot-target).1s.S
 	$(MAKE) $(build)=$(@D) .$(@F).1r.o .$(@F).1s.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
@@ -220,6 +222,7 @@ endif
 		> $(dot-target).2r.S
 	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).1 \
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+                  --source-name=$(@F).S \
 		> $(dot-target).2s.S
 	$(MAKE) $(build)=$(@D) .$(@F).2r.o .$(@F).2s.o
 	$(call compare-symbol-tables, $(dot-target).1r.o, $(dot-target).2r.o)
xen/tools/symbols.c +4 -0
@@ -66,6 +66,7 @@ int token_profit[0x10000];
 unsigned char best_table[256][2];
 unsigned char best_table_len[256];
 
+static const char *srcname = "xen-syms.S";
 
 static void usage(void)
 {
@@ -356,6 +357,7 @@ static void write_src(void)
 	printf("#define ALGN 4\n");
 	printf("#endif\n");
 
+	printf("\t.file \"%s\"\n", srcname);
 	printf("\t.section .rodata, \"a\"\n");
 
 	printf("#ifndef SYMBOLS_ORIGIN\n");
@@ -679,6 +681,8 @@ int main(int argc, char **argv)
 				unsorted = true;
 			else if (strcmp(argv[i], "--sort-by-name") == 0)
 				sort_by_name = 1;
+			else if (strncmp(argv[i], "--source-name=", 14) == 0)
+				srcname = argv[i] + 14;
 			else if (strcmp(argv[i], "--warn-dup") == 0)
 				warn_dup = true;
 			else if (strcmp(argv[i], "--error-dup") == 0)
#1 lore raw
Quoted 68 lines · Jan Beulich

If there are any local symbols in an object file, GNU ld will create an STT_FILE symbol derived from the object file name if there is none in the incoming symbol table. The object file name, however, varies between linking passes. As a result, symbol name compression can yield different results if any of those local symbols need retaining (Arm [and RISC-V] mapping symbols are omitted, for example). If that difference in compression would yield a difference in the sizes of symbol_names[] or symbols_token_table[], the compare-symbol-tables sanity check will fail.

Fixes d37d63d4b548 ("symbols: prefix static symbols with their source file names")

---
The observed problem was with a stub generated as Arm64 erratum 843419 workaround. Such stubs' symbols (imo wrongly) are associated with the last input object, rather than the input object they belong to. Also for other kinds of stubs, afaict. See
https://sourceware.org/bugzilla/show_bug.cgi?id=34140.

As per the above, having a Fixes: tag here is questionable.

xen/arch/x86/Makefile +4 -1
@@ -200,7 +200,8 @@ $(TARGET).efi: $(objtree)/prelink.o $(no
 ifeq ($(CONFIG_DEBUG_INFO),y)
 	$(if $(filter --strip-debug,$(EFI_LDFLAGS)),echo,:) "Will strip debug info from $(@F)"
 endif
-	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0s.S
+	$(objtree)/tools/symbols $(all_symbols) --source-name=$(@F).S --empty \
+		> $(dot-target).0s.S
 	$(MAKE) $(build)=$(@D) .$(@F).0s.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
 	          $(LD) $(call EFI_LDFLAGS,$(base)) -T $(obj)/efi.lds $< $(relocs-dummy) \
@@ -210,6 +211,7 @@ endif
 		> $(dot-target).1r.S
 	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).0 \
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+                  --source-name=$(@F).S \
 		> $(dot-target).1s.S
 	$(MAKE) $(build)=$(@D) .$(@F).1r.o .$(@F).1s.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
@@ -220,6 +222,7 @@ endif
 		> $(dot-target).2r.S
 	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).1 \
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+                  --source-name=$(@F).S \
 		> $(dot-target).2s.S
 	$(MAKE) $(build)=$(@D) .$(@F).2r.o .$(@F).2s.o
 	$(call compare-symbol-tables, $(dot-target).1r.o, $(dot-target).2r.o)
xen/tools/symbols.c +2 -0
@@ -66,6 +66,7 @@ int token_profit[0x10000];
 unsigned char best_table[256][2];
 unsigned char best_table_len[256];
 
+static const char *srcname = "xen-syms.S";
 
 static void usage(void)
 {
@@ -356,6 +357,7 @@ static void write_src(void)
 	printf("#define ALGN 4\n");
 	printf("#endif\n");
 
+	printf("\t.file \"%s\"\n", srcname);
 	printf("\t.section .rodata, \"a\"\n");
 
 	printf("#ifndef SYMBOLS_ORIGIN\n");

xen/tools/symbols.c int main(int argc, char **argv) · line 688

Quoted 8 lines
xen/tools/symbols.c +2 -0
@@ -679,6 +681,8 @@ int main(int argc, char **argv)
 				unsorted = true;
 			else if (strcmp(argv[i], "--sort-by-name") == 0)
 				sort_by_name = 1;
+			else if (strncmp(argv[i], "--source-name=", 14) == 0)
+				srcname = argv[i] + 14;
 			else if (strcmp(argv[i], "--warn-dup") == 0)
 				warn_dup = true;
 			else if (strcmp(argv[i], "--error-dup") == 0)

Why does x86 need to plumb the source name in, but the other architectures don't?

xen-syms.S suffices for both x86 builds AFAICT, so can't it just be unconditional?

~Andrew

#2 lore raw
Quoted 32 lines · Andrew Cooper
Quoted 19 lines · Jan Beulich
xen/tools/symbols.c +2 -0
@@ -66,6 +66,7 @@ int token_profit[0x10000];
 unsigned char best_table[256][2];
 unsigned char best_table_len[256];
 
+static const char *srcname = "xen-syms.S";
 
 static void usage(void)
 {
@@ -356,6 +357,7 @@ static void write_src(void)
 	printf("#define ALGN 4\n");
 	printf("#endif\n");
 
+	printf("\t.file \"%s\"\n", srcname);
 	printf("\t.section .rodata, \"a\"\n");
 
 	printf("#ifndef SYMBOLS_ORIGIN\n");

xen/tools/symbols.c int main(int argc, char **argv) · line 688

Quoted 8 lines
xen/tools/symbols.c +2 -0
@@ -679,6 +681,8 @@ int main(int argc, char **argv)
 				unsorted = true;
 			else if (strcmp(argv[i], "--sort-by-name") == 0)
 				sort_by_name = 1;
+			else if (strncmp(argv[i], "--source-name=", 14) == 0)
+				srcname = argv[i] + 14;
 			else if (strcmp(argv[i], "--warn-dup") == 0)
 				warn_dup = true;
 			else if (strcmp(argv[i], "--error-dup") == 0)

Why does x86 need to plumb the source name in, but the other architectures don't?

Quoted 2 lines

xen-syms.S suffices for both x86 builds AFAICT, so can't it just be unconditional?

It could. Yet I'd prefer the distinction between xen.efi and xen-syms to be recognizable (in case any dependent local symbol would show up).

Jan

Tested-by on v1 1/1
#3 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich

If there are any local symbols in an object file, GNU ld will create an STT_FILE symbol derived from the object file name if there is none in the incoming symbol table. The object file name, however, varies between linking passes. As a result, symbol name compression can yield different results if any of those local symbols need retaining (Arm [and RISC-V] mapping symbols are omitted, for example). If that difference in compression would yield a difference in the sizes of symbol_names[] or symbols_token_table[], the compare-symbol-tables sanity check will fail.

Quoted 3 lines
Fixes d37d63d4b548 ("symbols: prefix static symbols with their source file names")

I would like to note that with the current staging I can't reproduce this bug anymore with configs I have:

10d417b8b62e (HEAD -> staging, upstream/staging) xen/arm: skip holes in physical address space when setting up frametable 2611377cf9c9 xen/riscv: fix MMIO alignment check in imsic_init()
54ca0aadc821 x86/time: make do_settime() uses more accurate
4526d6763466 x86/time: make early NOW() uses slightly more precise
9f976dec039c xen: introduce CONFIG_HAS_DOMAIN_TYPE
bdb30883f352 iommu/amd-vi: do not zero IOMMU MMIO region
4f9457ece11a xsm/flask: Fix undefined behaviour in avc_dump_av()
4ff927133ebc EFI: adjust cfg file buffer freeing
96ffccef5a5f xvmalloc: adjust XVFREE() ordering
e8c1feab33cb CI: Refresh the Debian 12 cppcheck container
278953f6c155 (origin/staging, origin/HEAD) automation/gitlab: introduce macOS build jobs

But when I switched to origin/HEAD I can reproduce the bug and I applied the suggested patch on top of it and I don't see this bug anymore with this fix:

Thanks.

~ Oleksii

Acked-by on v1 1/1
#4 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich

If there are any local symbols in an object file, GNU ld will create an STT_FILE symbol derived from the object file name if there is none in the incoming symbol table. The object file name, however, varies between linking passes. As a result, symbol name compression can yield different results if any of those local symbols need retaining (Arm [and RISC-V] mapping symbols are omitted, for example). If that difference in compression would yield a difference in the sizes of symbol_names[] or symbols_token_table[], the compare-symbol-tables sanity check will fail.

Quoted 3 lines
Fixes d37d63d4b548 ("symbols: prefix static symbols with their source file names")
Quoted 30 lines

---
The observed problem was with a stub generated as Arm64 erratum 843419 workaround. Such stubs' symbols (imo wrongly) are associated with the last input object, rather than the input object they belong to. Also for other kinds of stubs, afaict. See
https://sourceware.org/bugzilla/show_bug.cgi?id=34140.

As per the above, having a Fixes: tag here is questionable.

xen/arch/x86/Makefile +3 -1
@@ -200,7 +200,8 @@ $(TARGET).efi: $(objtree)/prelink.o $(no
 ifeq ($(CONFIG_DEBUG_INFO),y)
 	$(if $(filter --strip-debug,$(EFI_LDFLAGS)),echo,:) "Will strip debug info from $(@F)"
 endif
-	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0s.S
+	$(objtree)/tools/symbols $(all_symbols) --source-name=$(@F).S --empty \
+		> $(dot-target).0s.S
 	$(MAKE) $(build)=$(@D) .$(@F).0s.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
 	          $(LD) $(call EFI_LDFLAGS,$(base)) -T $(obj)/efi.lds $< $(relocs-dummy) \
@@ -210,6 +211,7 @@ endif
 		> $(dot-target).1r.S
 	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).0 \
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+                  --source-name=$(@F).S \
 		> $(dot-target).1s.S
 	$(MAKE) $(build)=$(@D) .$(@F).1r.o .$(@F).1s.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \

xen/arch/x86/Makefile endif · line 226

Quoted 5 lines
xen/arch/x86/Makefile +1 -0
@@ -220,6 +222,7 @@ endif
 		> $(dot-target).2r.S
 	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).1 \
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+                  --source-name=$(@F).S \
 		> $(dot-target).2s.S

Wouldn't it be more accurate to use $(dot-target) as the source name?

Maybe $(notdir $(dot-target)).S?

I see the default is already set to the target filename for other arches, so not a big deal IMO.

Thanks, Roger.

#5 lore raw
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Jan Beulich

If there are any local symbols in an object file, GNU ld will create an STT_FILE symbol derived from the object file name if there is none in the incoming symbol table. The object file name, however, varies between linking passes. As a result, symbol name compression can yield different results if any of those local symbols need retaining (Arm [and RISC-V] mapping symbols are omitted, for example). If that difference in compression would yield a difference in the sizes of symbol_names[] or symbols_token_table[], the compare-symbol-tables sanity check will fail.

Quoted 5 lines
Quoted 3 lines
Fixes d37d63d4b548 ("symbols: prefix static symbols with their source file names")

Thanks.

Quoted 29 lines
Quoted 21 lines
xen/arch/x86/Makefile +3 -1
@@ -200,7 +200,8 @@ $(TARGET).efi: $(objtree)/prelink.o $(no
 ifeq ($(CONFIG_DEBUG_INFO),y)
 	$(if $(filter --strip-debug,$(EFI_LDFLAGS)),echo,:) "Will strip debug info from $(@F)"
 endif
-	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0s.S
+	$(objtree)/tools/symbols $(all_symbols) --source-name=$(@F).S --empty \
+		> $(dot-target).0s.S
 	$(MAKE) $(build)=$(@D) .$(@F).0s.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
 	          $(LD) $(call EFI_LDFLAGS,$(base)) -T $(obj)/efi.lds $< $(relocs-dummy) \
@@ -210,6 +211,7 @@ endif
 		> $(dot-target).1r.S
 	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).0 \
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+                  --source-name=$(@F).S \
 		> $(dot-target).1s.S
 	$(MAKE) $(build)=$(@D) .$(@F).1r.o .$(@F).1s.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \

xen/arch/x86/Makefile endif · line 226

Quoted 5 lines
xen/arch/x86/Makefile +1 -0
@@ -220,6 +222,7 @@ endif
 		> $(dot-target).2r.S
 	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).1 \
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+                  --source-name=$(@F).S \
 		> $(dot-target).2s.S

Wouldn't it be more accurate to use $(dot-target) as the source name?

Quoted 1 line

Maybe $(notdir $(dot-target)).S?

Why would that be better (more accurate)? The file names change, so the specified file is "virtual" anyway. I simply don't see why prepending a . would be helpful.

Quoted 2 lines

I see the default is already set to the target filename for other arches, so not a big deal IMO.

It's a "virtual" filename also there. No real xen-syms.S is ever created.

Jan