dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.53k stars 4.54k forks source link

Xcode 16-beta compilation error: non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs #104105

Open vcsjones opened 5 days ago

vcsjones commented 5 days ago

I was doing a little bit of scouting on macOS 16 / Xcode 16 and ran in to a compiler error on Xcode 16.

The gist of the error is

  <instantiation>:5:1: error: non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs

Repeated many times. The full build log is available at https://gist.github.com/vcsjones/1649f2fb8b19ab86428582b6884229c0

Note this does not require a beta of macOS, only the developer tools.

dotnet-policy-service[bot] commented 5 days ago

Tagging subscribers to this area: @mangod9 See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 4 days ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.

filipnavara commented 4 days ago

I may take a look. Was it Xcode 16 beta 1 or 2?

vcsjones commented 4 days ago

I may take a look. Was it Xcode 16 beta 1 or 2?

Beta 2. 16A5171r.

filipnavara commented 4 days ago

Beta 2. 16A5171r.

That explains it. I run it earlier with Beta 1 and that still builds on my machine (cannot completely rule out that Cmake cache still forced some other Xcode version)... I'll switch to Beta 2 soon.

filipnavara commented 4 days ago

I can reproduce. At first sight, it seems that using .alt_entry should be possible (https://github.com/llvm/llvm-project/pull/82268):

--- a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc
+++ b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc
@@ -24,9 +24,11 @@ C_FUNC(\Name):
 .endm

 .macro ALTERNATE_ENTRY Name
-        .global C_FUNC(\Name)
 #if !defined(__APPLE__)
+        .global C_FUNC(\Name)
         .hidden C_FUNC(\Name)
+#else
+        .alt_entry C_FUNC(\Name)
 #endif
 C_FUNC(\Name):
 .endm

It still fails with the following errors:

  [ 37%] Building ASM object nativeaot/Runtime/Full/CMakeFiles/Runtime.ServerGC.dir/__/arm64/PInvoke.S.o
  <instantiation>:2:9: error: invalid CFI advance_loc expression
          .cfi_restore fp
          ^
  <instantiation>:2:9: error: invalid CFI advance_loc expression
          .cfi_restore fp
          ^
  <instantiation>:2:9: error: invalid CFI advance_loc expression
          .cfi_adjust_cfa_offset -0x60
          ^
  <instantiation>:2:9: error: invalid CFI advance_loc expression
          .cfi_adjust_cfa_offset -0x40
          ^
  make[3]: *** [nativeaot/Runtime/Full/CMakeFiles/Runtime.WorkstationGC.dir/__/arm64/UniversalTransition.S.o] Error 1
  make[3]: *** Waiting for unfinished jobs....
  make[3]: *** [nativeaot/Runtime/Full/CMakeFiles/Runtime.WorkstationGC.dir/__/arm64/ExceptionHandling.S.o] Error 1
  <instantiation>:2:9: error: invalid CFI advance_loc expression
          .cfi_adjust_cfa_offset -0x60
          ^
  <instantiation>:2:9: error: invalid CFI advance_loc expression
          .cfi_adjust_cfa_offset -0x40
          ^
  [ 37%] Building ASM object nativeaot/Runtime/Full/CMakeFiles/Runtime.ServerGC.dir/__/arm64/InteropThunksHelpers.S.o
  [ 37%] Building ASM object nativeaot/Runtime/Full/CMakeFiles/Runtime.ServerGC.dir/__/arm64/UniversalTransition.S.o
  make[3]: *** [nativeaot/Runtime/Full/CMakeFiles/Runtime.ServerGC.dir/__/arm64/ExceptionHandling.S.o] Error 1
  make[3]: *** Waiting for unfinished jobs....
  [ 37%] Building ASM object nativeaot/Runtime/Full/CMakeFiles/Runtime.ServerGC.dir/__/arm64/StubDispatch.S.o
  [ 37%] Building ASM object nativeaot/Runtime/Full/CMakeFiles/Runtime.ServerGC.dir/__/arm64/WriteBarriers.S.o
  [ 37%] Building ASM object nativeaot/Runtime/Full/CMakeFiles/Runtime.ServerGC.dir/__/arm64/ThunkPoolThunks.S.o
  make[2]: *** [nativeaot/Runtime/Full/CMakeFiles/Runtime.WorkstationGC.dir/all] Error 2
  make[2]: *** Waiting for unfinished jobs....
  <instantiation>:2:9: error: invalid CFI advance_loc expression
          .cfi_restore fp
          ^
  <instantiation>:2:9: error: invalid CFI advance_loc expression
          .cfi_restore fp
          ^

Hopefully it will be relatively easy to figure it out and the linker won't complain about the .alt_entry.

filipnavara commented 4 days ago

So, on the upside... the .alt_entry seems to do the trick for the first error, and links. On the downside, the "invalid CFI advance_loc expression" error could be a compiler bug from a change that was supposed to detect the same condition as the other error (https://github.com/llvm/llvm-project/commit/0b0672773e8b2ed01ad3fce103f4d84becfdd1ed).

This doesn't compile either:

.section __TEXT,__text
.globl _foo
_foo:
  .cfi_startproc
  sub sp, sp, 8
  .cfi_adjust_cfa_offset 8
  .alt_entry _bar
_bar:
  add sp, sp, 8
  .cfi_adjust_cfa_offset -8
  ret
  .cfi_endproc

with the error

src/test.S:10:3: error: invalid CFI advance_loc expression
  .cfi_adjust_cfa_offset -8

I'll have to sleep on it, and read more about the .alt_entry semantics.

filipnavara commented 1 day ago

Filed as LLVM issue: https://github.com/llvm/llvm-project/issues/97116 We will still need to switch to using .alt_entry, and we may need to do that in ObjWriter as well (FYI @ivanpovazan).