Skip to content

Commit cd667e6

Browse files
committed
Work around some more GAS bugs
1 parent 9d32047 commit cd667e6

File tree

8 files changed

+461
-449
lines changed

8 files changed

+461
-449
lines changed

kos/include/cfi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ __ASM_L(.endm)
104104

105105
__ASM_L(.macro .cfi_escape_uleb128 value:req)
106106
__ASM_L( .if (__ASM_ARG(\value)) <= 0x7f)
107-
__ASM_L( .cfi_escape __ASM_ARG(\value) + 0) /* "+0" required to work around gas bug */
107+
__ASM_L( .cfi_escape (__ASM_ARG(\value) + 0)) /* "+0" required to work around gas bug */
108108
__ASM_L( .else)
109109
__ASM_L( .cfi_escape ((__ASM_ARG(\value)) & 0x7f) | 0x80)
110110
__ASM_L( .cfi_escape_uleb128 (__ASM_ARG(\value)) >> 7)
@@ -119,15 +119,15 @@ __ASM_L( .else)
119119
__ASM_L( .Lvalue = ~(~(__ASM_ARG(\value)) / 128))
120120
__ASM_L( .endif)
121121
__ASM_L( .if ((.Lvalue == 0) && ((.Lbyte & 0x40) == 0)) || ((.Lvalue == -1) && ((.Lbyte & 0x40) != 0)))
122-
__ASM_L( .cfi_escape .Lbyte + 0) /* "+0" required to work around gas bug */
122+
__ASM_L( .cfi_escape (.Lbyte + 0)) /* "+0" required to work around gas bug */
123123
__ASM_L( .else)
124124
__ASM_L( .cfi_escape (.Lbyte | 0x80)) /* Extra parens required to work around gas bug */
125125
__ASM_L( .cfi_escape_sleb128 .Lvalue)
126126
__ASM_L( .endif)
127127
__ASM_L(.endm)
128128

129129
__ASM_L(.macro __cfi_escape_breg regno:req)
130-
__ASM_L( .cfi_escape 0x70 + __ASM_ARG(\regno))
130+
__ASM_L( .cfi_escape (0x70 + __ASM_ARG(\regno)))
131131
__ASM_L(.endm)
132132

133133

kos/include/i386-kos/asm/cfi.h

Lines changed: 425 additions & 425 deletions
Large diffs are not rendered by default.

kos/misc/libgen/cfi/comp.dee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,9 @@ function outputBytesForAssembly(bytes: {int | string...},
15201520
for (local b: line) b !is int ? b : b.hex(2)), lineSuffix);
15211521
#else
15221522
for (local line: bytes.segments(bytesPerLine))
1523-
print outputFile: (linePrefix, "\t.cfi_escape ", ",".join(line), lineSuffix);
1523+
print outputFile: (linePrefix, "\t.cfi_escape ", ",".join(
1524+
/* NOTE: The extra parenthesis for custom bytes is needed to work around a GAS bug */
1525+
for (local b: line) b is int ? b : f"({b})"), lineSuffix);
15241526
#endif
15251527
}
15261528

kos/src/kernel/core/arch/i386/debugger/rt32-enter.S.inl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,13 @@ L(.Lalready_active):
291291
EXTERN(x86_dbg_exitstate_b1)
292292
EXTERN(x86_dbg_exitstate_b2)
293293
EXTERN(x86_dbg_exitstate_b3)
294-
.cfi_escape DW_CFA_def_cfa_expression, 5
295-
.cfi_escape DW_OP_addr, x86_dbg_exitstate_b0, x86_dbg_exitstate_b1, \
296-
x86_dbg_exitstate_b2, x86_dbg_exitstate_b3
294+
.cfi_escape DW_CFA_def_cfa_expression
295+
.cfi_escape 5
296+
.cfi_escape DW_OP_addr
297+
.cfi_escape (x86_dbg_exitstate_b0 + 0)
298+
.cfi_escape (x86_dbg_exitstate_b1 + 0)
299+
.cfi_escape (x86_dbg_exitstate_b2 + 0)
300+
.cfi_escape (x86_dbg_exitstate_b3 + 0)
297301
ASM_CFI_OFFSET_RESTORE_FCPUSTATE(0)
298302

299303
/* Fixup control registers. */

kos/src/kernel/core/arch/i386/debugger/rt32.S

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#ifndef GUARD_KERNEL_CORE_ARCH_I386_DEBUGGER_RT32_S
2121
#define GUARD_KERNEL_CORE_ARCH_I386_DEBUGGER_RT32_S 1
22+
#define __ASSEMBLER__ 1
2223

2324
#include <debugger/rt.h>
2425

@@ -39,9 +40,13 @@
3940
EXTERN(x86_dbg_exitstate_b3);
4041

4142
/* Encode CFA as `x86_dbg_exitstate' */
42-
.cfi_escape DW_CFA_def_cfa_expression, 5
43-
.cfi_escape DW_OP_addr, x86_dbg_exitstate_b0, x86_dbg_exitstate_b1, \
44-
x86_dbg_exitstate_b2, x86_dbg_exitstate_b3
43+
.cfi_escape DW_CFA_def_cfa_expression
44+
.cfi_escape 5
45+
.cfi_escape DW_OP_addr
46+
.cfi_escape (x86_dbg_exitstate_b0 + 0)
47+
.cfi_escape (x86_dbg_exitstate_b1 + 0)
48+
.cfi_escape (x86_dbg_exitstate_b2 + 0)
49+
.cfi_escape (x86_dbg_exitstate_b3 + 0)
4550
ASM_CFI_OFFSET_RESTORE_FCPUSTATE(0)
4651
nop /* For tracebacks. */
4752
PUBLIC_FUNCTION(dbg_exit)

kos/src/kernel/core/arch/i386/debugger/rt64.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#ifndef GUARD_KERNEL_CORE_ARCH_I386_DEBUGGER_RT32_S
2121
#define GUARD_KERNEL_CORE_ARCH_I386_DEBUGGER_RT32_S 1
22+
#define __ASSEMBLER__ 1
2223

2324
#include <debugger/rt.h>
2425

kos/src/kernel/core/arch/i386/sched/rpc.S

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,34 +238,34 @@ print("#endif /" "* __I386_NO_VM86 *" "/");
238238
print("#endif /" "* !__x86_64__ *" "/");
239239
]]]*/
240240
#ifdef __x86_64__
241-
__ASM_L( .cfi_escape 22,16,18,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_RIP,155,6)
241+
__ASM_L( .cfi_escape 22,16,18,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_RIP),155,6)
242242
__ASM_L( .cfi_escape 47,2,0,128,0)
243-
__ASM_L( .cfi_escape 22,51,19,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_CS,155,6)
243+
__ASM_L( .cfi_escape 22,51,19,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_CS),155,6)
244244
__ASM_L( .cfi_escape 47,3,0,146,51,0)
245-
__ASM_L( .cfi_escape 22,49,19,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_RFLAGS,155,6)
245+
__ASM_L( .cfi_escape 22,49,19,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_RFLAGS),155,6)
246246
__ASM_L( .cfi_escape 47,3,0,146,49,0)
247-
__ASM_L( .cfi_escape 22,7,18,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_RSP,155,6)
247+
__ASM_L( .cfi_escape 22,7,18,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_RSP),155,6)
248248
__ASM_L( .cfi_escape 47,2,0,119,0)
249-
__ASM_L( .cfi_escape 22,52,19,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_SS,155,6)
249+
__ASM_L( .cfi_escape 22,52,19,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_SS),155,6)
250250
__ASM_L( .cfi_escape 47,3,0,146,52,0)
251251
#else /* __x86_64__ */
252-
__ASM_L( .cfi_escape 22,8,18,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_EIP,155,6)
252+
__ASM_L( .cfi_escape 22,8,18,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_EIP),155,6)
253253
__ASM_L( .cfi_escape 47,2,0,120,0)
254-
__ASM_L( .cfi_escape 22,41,19,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_CS,155,6)
254+
__ASM_L( .cfi_escape 22,41,19,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_CS),155,6)
255255
__ASM_L( .cfi_escape 47,3,0,146,41,0)
256-
__ASM_L( .cfi_escape 22,9,18,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS,155,6)
256+
__ASM_L( .cfi_escape 22,9,18,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS),155,6)
257257
__ASM_L( .cfi_escape 47,2,0,121,0)
258258
#ifndef __I386_NO_VM86
259-
__ASM_L( .cfi_escape 22,40,31,47,3,0,75,79,83,47,19,0,8,this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS,155,6)
259+
__ASM_L( .cfi_escape 22,40,31,47,3,0,75,79,83,47,19,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS),155,6)
260260
__ASM_L( .cfi_escape 16,128,128,8,26,32,40,6,0,116,8,6,47,3,0,146)
261261
__ASM_L( .cfi_escape 40,0)
262-
__ASM_L( .cfi_escape 22,43,31,47,3,0,75,79,83,47,19,0,8,this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS,155,6)
262+
__ASM_L( .cfi_escape 22,43,31,47,3,0,75,79,83,47,19,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS),155,6)
263263
__ASM_L( .cfi_escape 16,128,128,8,26,32,40,6,0,116,12,6,47,3,0,146)
264264
__ASM_L( .cfi_escape 43,0)
265-
__ASM_L( .cfi_escape 22,44,31,47,3,0,75,79,83,47,19,0,8,this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS,155,6)
265+
__ASM_L( .cfi_escape 22,44,31,47,3,0,75,79,83,47,19,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS),155,6)
266266
__ASM_L( .cfi_escape 16,128,128,8,26,32,40,6,0,116,16,6,47,3,0,146)
267267
__ASM_L( .cfi_escape 44,0)
268-
__ASM_L( .cfi_escape 22,45,31,47,3,0,75,79,83,47,19,0,8,this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS,155,6)
268+
__ASM_L( .cfi_escape 22,45,31,47,3,0,75,79,83,47,19,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_EFLAGS),155,6)
269269
__ASM_L( .cfi_escape 16,128,128,8,26,32,40,6,0,116,20,6,47,3,0,146)
270270
__ASM_L( .cfi_escape 45,0)
271271
#endif /* __I386_NO_VM86 */

kos/src/kernel/core/arch/i386/syscall/syscall-syscall-64.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ PUBLIC_FUNCTION(x86_syscall64_syscall)
6666
ret
6767
1: push %rsp
6868
]]]*/
69-
.cfi_escape 22,7,18,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_RSP,155,6
69+
.cfi_escape 22,7,18,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_RSP),155,6
7070
.cfi_escape 47,2,0,119,0
7171
/*[[[end]]]*/
7272

@@ -136,7 +136,7 @@ PUBLIC_FUNCTION(x86_syscall64_syscall_traced)
136136
ret
137137
1: push %rsp
138138
]]]*/
139-
.cfi_escape 22,7,18,47,3,0,75,79,83,47,7,0,8,this_x86_sysret_iret + OFFSET_IRREGS_RSP,155,6
139+
.cfi_escape 22,7,18,47,3,0,75,79,83,47,7,0,8,(this_x86_sysret_iret + OFFSET_IRREGS_RSP),155,6
140140
.cfi_escape 47,2,0,119,0
141141
/*[[[end]]]*/
142142

0 commit comments

Comments
 (0)