Browse Source

[librm] Ensure that inline code symbols are unique

Commit 6149e0a ("[librm] Provide symbols for inline code placed into
other sections") may cause build failures due to duplicate label names
if the compiler chooses to duplicate inline assembly code.

Fix by using the "%=" special format string to include a
guaranteed-unique number within the label name.

The "%=" will be expanded only if constraints exist for the inline
assembly.  This fix therefore requires that all REAL_CODE() fragments
use a (possibly empty) constraint list.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 6 years ago
parent
commit
bc85368cdd

+ 1
- 1
src/arch/x86/core/dumpregs.c View File

@@ -7,7 +7,7 @@ void __asmcall _dump_regs ( struct i386_all_regs *ix86 ) {
7 7
 		TEXT16_CODE ( ".globl dump_regs\n\t"
8 8
 			      "\ndump_regs:\n\t"
9 9
 			      VIRT_CALL ( _dump_regs )
10
-			      "ret\n\t" ) );
10
+			      "ret\n\t" ) : );
11 11
 
12 12
 	printf ( "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
13 13
 		 "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"

+ 1
- 1
src/arch/x86/include/librm.h View File

@@ -255,7 +255,7 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size );
255 255
 #endif
256 256
 
257 257
 /* LINE_SYMBOL: declare a symbol for the current source code line */
258
-#define LINE_SYMBOL _S2 ( OBJECT ) "__line_" _S2 ( __LINE__ ) ":"
258
+#define LINE_SYMBOL _S2 ( OBJECT ) "__line_" _S2 ( __LINE__ ) "__%=:"
259 259
 
260 260
 /* TEXT16_CODE: declare a fragment of code that resides in .text16 */
261 261
 #define TEXT16_CODE( asm_code_str )			\

+ 2
- 2
src/arch/x86/interface/pcbios/bios_console.c View File

@@ -521,12 +521,12 @@ static void bios_inject_startup ( void ) {
521 521
 	__asm__ __volatile__ (
522 522
 		TEXT16_CODE ( "\nint16_wrapper:\n\t"
523 523
 			      "pushfw\n\t"
524
-			      "cmpb $0, %cs:bios_inject_lock\n\t"
524
+			      "cmpb $0, %%cs:bios_inject_lock\n\t"
525 525
 			      "jnz 1f\n\t"
526 526
 			      VIRT_CALL ( bios_inject )
527 527
 			      "\n1:\n\t"
528 528
 			      "popfw\n\t"
529
-			      "ljmp *%cs:int16_vector\n\t" ) );
529
+			      "ljmp *%%cs:int16_vector\n\t" ) : );
530 530
 
531 531
 	/* Hook INT 16 */
532 532
 	hook_bios_interrupt ( 0x16, ( ( intptr_t ) int16_wrapper ),

+ 1
- 1
src/arch/x86/interface/pcbios/bios_reboot.c View File

@@ -48,7 +48,7 @@ static void bios_reboot ( int warm ) {
48 48
 	put_real ( flag, BDA_SEG, BDA_REBOOT );
49 49
 
50 50
 	/* Jump to system reset vector */
51
-	__asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) );
51
+	__asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : );
52 52
 }
53 53
 
54 54
 /**

+ 3
- 3
src/arch/x86/interface/syslinux/comboot_call.c View File

@@ -663,7 +663,7 @@ void hook_comboot_interrupts ( ) {
663 663
 			      VIRT_CALL ( int20 )
664 664
 			      "clc\n\t"
665 665
 			      "call patch_cf\n\t"
666
-		              "iret\n\t" ) );
666
+		              "iret\n\t" ) : );
667 667
 
668 668
 	hook_bios_interrupt ( 0x20, ( intptr_t ) int20_wrapper, &int20_vector );
669 669
 
@@ -672,7 +672,7 @@ void hook_comboot_interrupts ( ) {
672 672
 			      VIRT_CALL ( int21 )
673 673
 			      "clc\n\t"
674 674
 			      "call patch_cf\n\t"
675
-		              "iret\n\t" ) );
675
+		              "iret\n\t" ) : );
676 676
 
677 677
 	hook_bios_interrupt ( 0x21, ( intptr_t ) int21_wrapper, &int21_vector );
678 678
 
@@ -681,7 +681,7 @@ void hook_comboot_interrupts ( ) {
681 681
 			      VIRT_CALL ( int22 )
682 682
 			      "clc\n\t"
683 683
 			      "call patch_cf\n\t"
684
-		              "iret\n\t" ) );
684
+		              "iret\n\t" ) : );
685 685
 
686 686
 	hook_bios_interrupt ( 0x22, ( intptr_t ) int22_wrapper, &int22_vector );
687 687
 }

+ 1
- 1
src/arch/x86/transitions/librm_test.c View File

@@ -97,7 +97,7 @@ static void librm_test_exec ( void ) {
97 97
 	/* Profile complete real-mode call cycle */
98 98
 	for ( i = 0 ; i < PROFILE_COUNT ; i++ ) {
99 99
 		profile_start ( &real_call_profiler );
100
-		__asm__ __volatile__ ( REAL_CODE ( "" ) );
100
+		__asm__ __volatile__ ( REAL_CODE ( "" ) : );
101 101
 		profile_stop ( &real_call_profiler );
102 102
 	}
103 103
 

Loading…
Cancel
Save