@@ -54,13 +54,21 @@ pub(super) fn dynamic_table_addr() -> *const Elf_Dyn {
5454 asm ! (
5555 ".weak _DYNAMIC" ,
5656 ".hidden _DYNAMIC" ,
57- "call 0f " ,
57+ "call 2f " ,
5858 ".cfi_adjust_cfa_offset 4" ,
59- "0 :" ,
59+ "2 :" ,
6060 "pop {0}" ,
6161 ".cfi_adjust_cfa_offset -4" ,
62- "1:" ,
63- "add {0}, offset _GLOBAL_OFFSET_TABLE_+(1b-0b)" ,
62+ "3:" ,
63+ // Use "2" and "3" instead of "0" and "1" because "0b" and "1b" are
64+ // parsed as binary literals rather than as label references. And,
65+ // hard-code the value `1` here because the assembler doesn't support
66+ // the symbol difference expression in an instruction operand
67+ // context. Then, check that the hard-coded value is what we expect.
68+ ".ifne (3b-2b)-1" ,
69+ ".error \" The pop opcode is expected to be 1 byte long.\" " ,
70+ ".endif" ,
71+ "add {0}, offset _GLOBAL_OFFSET_TABLE_+1" ,
6472 "lea {0}, [{0} + _DYNAMIC@GOTOFF]" ,
6573 out( reg) addr
6674 )
@@ -75,13 +83,17 @@ pub(super) fn ehdr_addr() -> *const Elf_Ehdr {
7583 let addr;
7684 unsafe {
7785 asm ! (
78- "call 0f " ,
86+ "call 2f " ,
7987 ".cfi_adjust_cfa_offset 4" ,
80- "0 :" ,
88+ "2 :" ,
8189 "pop {0}" ,
8290 ".cfi_adjust_cfa_offset -4" ,
83- "1:" ,
84- "add {0}, offset _GLOBAL_OFFSET_TABLE_+(1b-0b)" ,
91+ "3:" ,
92+ // See the comment by similar code in `dynamic_table_addr`.
93+ ".ifne (3b-2b)-1" ,
94+ ".error \" The pop opcode is expected to be 1 byte long.\" " ,
95+ ".endif" ,
96+ "add {0}, offset _GLOBAL_OFFSET_TABLE_+1" ,
8597 "lea {0}, [{0} + __ehdr_start@GOTOFF]" ,
8698 out( reg) addr
8799 )
@@ -245,7 +257,7 @@ pub(super) unsafe fn clone(
245257 // in the child.
246258 "int 0x80" , // Do the `clone` system call.
247259 "test eax, eax" , // Branch if we're in the parent.
248- "jnz 0f " ,
260+ "jnz 2f " ,
249261
250262 // Child thread.
251263 "pop edi" , // Load `fn_` from the child stack.
@@ -259,7 +271,7 @@ pub(super) unsafe fn clone(
259271 "jmp {entry}" , // Call `entry`.
260272
261273 // Parent thread.
262- "0 :" ,
274+ "2 :" ,
263275 "pop ebp" , // Restore incoming register value.
264276 "pop esi" , // Restore incoming register value.
265277
0 commit comments