Commit 2dd0823
committed
[cc] aarch64 varargs fixes; new CLI arg
Summary
Root Cause of CI Failures
The failing tests (varargs_caller_comprehensive and varargs_float_args)
were caused by a calling convention mismatch on Apple ARM64
(Darwin/macOS).
The Apple ARM64 ABI differs from standard AAPCS64 for variadic functions:
- AAPCS64 (Linux): Variadic arguments use normal register allocation
(x0-x7 for integers, d0-d7 for floats)
- Apple ARM64 (Darwin): ALL variadic arguments must be passed on the
stack, not in registers
Our codegen was using the same register-based passing for all platforms,
which worked on Linux but failed on the macOS CI runners (Apple Silicon).
Fix Applied
Modified cc/arch/aarch64/codegen.rs emit_call() function to:
1. Detect Darwin variadic calls via insn.variadic_arg_start and target.os
== MacOS
2. For Darwin variadic calls: Pass fixed args in registers as normal, but
push all variadic arguments onto the stack
3. For Linux/FreeBSD: Keep existing behavior (registers for all args)
Assembly Comparison
Before (incorrect for Darwin):
mov w2, #42 ; variadic arg in register - WRONG
bl _sprintf
After (correct for Darwin):
mov w9, #42
str x9, [sp, #-16]! ; variadic arg on stack - CORRECT
bl _sprintf
add sp, sp, #16
Additional Feature
Added --print-targets CLI argument that displays available target
architectures, matching clang's behavior:
$ ./target/release/pcc --print-targets
Registered Targets:
aarch64 - AArch64 (little endian)
x86-64 - 64-bit X86: EM64T and AMD64
Files Modified
- cc/arch/aarch64/codegen.rs - Fixed variadic argument passing for Darwin
- cc/main.rs - Added --print-targets argument
Test Results
- All 313 tests pass locally on x86-64
- The varargs tests should now pass on the macOS aarch64 CI runner
Sources:
- https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst
- https://dyncall.org/docs/manual/manualse11.html1 parent 5485bd7 commit 2dd0823
2 files changed
+149
-51
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2984 | 2984 | | |
2985 | 2985 | | |
2986 | 2986 | | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
2987 | 2991 | | |
2988 | 2992 | | |
2989 | 2993 | | |
2990 | 2994 | | |
2991 | 2995 | | |
2992 | 2996 | | |
2993 | 2997 | | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
2994 | 3003 | | |
2995 | 3004 | | |
2996 | 3005 | | |
| |||
3018 | 3027 | | |
3019 | 3028 | | |
3020 | 3029 | | |
3021 | | - | |
3022 | | - | |
3023 | | - | |
3024 | | - | |
3025 | | - | |
3026 | | - | |
3027 | | - | |
3028 | | - | |
3029 | | - | |
3030 | | - | |
3031 | | - | |
3032 | | - | |
3033 | | - | |
3034 | | - | |
3035 | | - | |
3036 | | - | |
3037 | | - | |
3038 | | - | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
| 3038 | + | |
| 3039 | + | |
| 3040 | + | |
| 3041 | + | |
| 3042 | + | |
| 3043 | + | |
| 3044 | + | |
| 3045 | + | |
3039 | 3046 | | |
3040 | | - | |
3041 | | - | |
3042 | | - | |
3043 | | - | |
| 3047 | + | |
| 3048 | + | |
3044 | 3049 | | |
3045 | 3050 | | |
3046 | 3051 | | |
3047 | | - | |
3048 | | - | |
3049 | | - | |
| 3052 | + | |
| 3053 | + | |
| 3054 | + | |
| 3055 | + | |
3050 | 3056 | | |
3051 | | - | |
3052 | | - | |
3053 | | - | |
3054 | | - | |
3055 | | - | |
3056 | | - | |
3057 | | - | |
3058 | | - | |
| 3057 | + | |
| 3058 | + | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
| 3073 | + | |
| 3074 | + | |
| 3075 | + | |
| 3076 | + | |
| 3077 | + | |
| 3078 | + | |
| 3079 | + | |
| 3080 | + | |
| 3081 | + | |
3059 | 3082 | | |
3060 | | - | |
| 3083 | + | |
3061 | 3084 | | |
3062 | 3085 | | |
3063 | 3086 | | |
3064 | 3087 | | |
3065 | 3088 | | |
3066 | 3089 | | |
3067 | | - | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
| 3093 | + | |
| 3094 | + | |
| 3095 | + | |
| 3096 | + | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
| 3100 | + | |
3068 | 3101 | | |
3069 | | - | |
3070 | | - | |
3071 | | - | |
3072 | | - | |
3073 | | - | |
3074 | | - | |
3075 | | - | |
3076 | | - | |
3077 | | - | |
3078 | | - | |
3079 | | - | |
3080 | | - | |
3081 | | - | |
3082 | | - | |
3083 | | - | |
3084 | 3102 | | |
3085 | 3103 | | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
| 3107 | + | |
| 3108 | + | |
| 3109 | + | |
| 3110 | + | |
| 3111 | + | |
| 3112 | + | |
| 3113 | + | |
| 3114 | + | |
| 3115 | + | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
| 3138 | + | |
| 3139 | + | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
3086 | 3172 | | |
3087 | 3173 | | |
3088 | 3174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| |||
331 | 335 | | |
332 | 336 | | |
333 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
334 | 346 | | |
335 | 347 | | |
336 | 348 | | |
| |||
0 commit comments