public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode
@ 2023-09-29  0:16 amy at amyspark dot me
  2023-09-29  0:17 ` [Bug lto/111635] " amy at amyspark dot me
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: amy at amyspark dot me @ 2023-09-29  0:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111635

            Bug ID: 111635
           Summary: Objects built with -flto cannot be linked with Xcode
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amy at amyspark dot me
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 56013
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56013&action=edit
Full build failure log

Hi,

This is to report that GCC is feeding broken assembly to AppleClang as part of
LTO linking.

The output looks as follows:

/var/folders/l1/b3htrbqd3w3f32x9lk1yll6h0000gn/T//ccPBRnCj.s:1628:18: error:
non-local symbol required in directive
        .private_extern LPBX0.lto_priv.0
                        ^
/var/folders/l1/b3htrbqd3w3f32x9lk1yll6h0000gn/T//ccPBRnCj.s:1629:9: error:
non-local symbol required in directive
        .globl LPBX0.lto_priv.0

(snip)

followed by the corresponding:

make: ***
[/var/folders/l1/b3htrbqd3w3f32x9lk1yll6h0000gn/T//ccVBnAk5.ltrans1.ltrans.o]
Error 1
make: *** Waiting for unfinished jobs....
/var/folders/l1/b3htrbqd3w3f32x9lk1yll6h0000gn/T//ccpBZ3qu.s:360623:1: error:
assembler local symbol 'LPBX0.lto_priv.0' not defined

^

(snip)

I am not able to attach the resulting assembly as this happens during the
linking step and the files are lost upon failure. It is still easily
reproducible by building https://github.com/blackmagic-debug/bmpflash with
`meson setup build -Db_lto=true --buildtype=debug` followed by `meson compile
-C build`.

This was tested with GCC 13.2.0 as shipped by Homebrew, Xcode 13.2.1.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug lto/111635] Objects built with -flto cannot be linked with Xcode
  2023-09-29  0:16 [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode amy at amyspark dot me
@ 2023-09-29  0:17 ` amy at amyspark dot me
  2023-09-29  0:27 ` [Bug target/111635] " pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: amy at amyspark dot me @ 2023-09-29  0:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111635

--- Comment #1 from Amyspark <amy at amyspark dot me> ---
Created attachment 56014
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56014&action=edit
Full compiler version

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/111635] Objects built with -flto cannot be linked with Xcode
  2023-09-29  0:16 [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode amy at amyspark dot me
  2023-09-29  0:17 ` [Bug lto/111635] " amy at amyspark dot me
@ 2023-09-29  0:27 ` pinskia at gcc dot gnu.org
  2023-09-29  0:30 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-29  0:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111635

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm:
```
static void
build_gcov_info_var_registration (tree gcov_info_type)
{
  tree var = build_decl (BUILTINS_LOCATION,
                         VAR_DECL, NULL_TREE,
                         build_pointer_type (gcov_info_type));
  TREE_STATIC (var) = 1;
  TREE_READONLY (var) = 1;
  char name_buf[32];
  ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 2);
  DECL_NAME (var) = get_identifier (name_buf);
  get_section (profile_info_section, SECTION_UNNAMED, NULL);
  set_decl_section_name (var, profile_info_section);
  mark_decl_referenced (var);
  DECL_INITIAL (var) = build_fold_addr_expr (gcov_info_var);
  varpool_node::finalize_decl (var);
}
```
```
/* Make local constant labels linker-visible, so that if one follows a
   weak_global constant, ld64 will be able to separate the atoms.  */
#undef ASM_GENERATE_INTERNAL_LABEL
#define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)   \
  do {                                                  \
    if (strcmp ("LC", PREFIX) == 0)                     \
      sprintf (LABEL, "*%s%ld", "lC", (long)(NUM));     \
    else if (strcmp ("Lubsan_data", PREFIX) == 0)       \
      sprintf (LABEL, "*%s%ld", "lubsan_data", (long)(NUM));\
    else if (strcmp ("Lubsan_type", PREFIX) == 0)       \
      sprintf (LABEL, "*%s%ld", "lubsan_type", (long)(NUM));\
    else if (strcmp ("LASAN", PREFIX) == 0)     \
      sprintf (LABEL, "*%s%ld", "lASAN", (long)(NUM));\
    else if (strcmp ("LTRAMP", PREFIX) == 0)    \
      sprintf (LABEL, "*%s%ld", "lTRAMP", (long)(NUM));\
    else                                                \
      sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM));   \
  } while (0)
```

Looks like this PREFIX needs to be special cased too ...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/111635] Objects built with -flto cannot be linked with Xcode
  2023-09-29  0:16 [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode amy at amyspark dot me
  2023-09-29  0:17 ` [Bug lto/111635] " amy at amyspark dot me
  2023-09-29  0:27 ` [Bug target/111635] " pinskia at gcc dot gnu.org
@ 2023-09-29  0:30 ` pinskia at gcc dot gnu.org
  2023-10-30 16:48 ` fxcoudert at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-29  0:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111635

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Oh 0 is from:
  /* Build the gcov info var, this is referred to in its own
     initializer.  */
  gcov_info_var = build_decl (BUILTINS_LOCATION,
                              VAR_DECL, NULL_TREE, gcov_info_type);
  TREE_STATIC (gcov_info_var) = 1;
  ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 0);
  DECL_NAME (gcov_info_var) = get_identifier (name_buf);


But I think LPBX still needs a special case there ...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/111635] Objects built with -flto cannot be linked with Xcode
  2023-09-29  0:16 [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode amy at amyspark dot me
                   ` (2 preceding siblings ...)
  2023-09-29  0:30 ` pinskia at gcc dot gnu.org
@ 2023-10-30 16:48 ` fxcoudert at gcc dot gnu.org
  2023-10-30 16:51 ` fxcoudert at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2023-10-30 16:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111635

Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu.org

--- Comment #4 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
(In reply to Amyspark from comment #0)
> It is still easily
> reproducible by building https://github.com/blackmagic-debug/bmpflash with
> `meson setup build -Db_lto=true --buildtype=debug` followed by `meson
> compile -C build`.

I tried but could not reproduce on aarch64-apple-darwin23. The first try failed
because the code was updated and refuses to build with LTO. I checked out
commit f87ad307ddc1822e3a770e234ae2adcbe5ea855b

The second try failed because:

libusb| Run-time dependency iokit found: NO (tried framework)
deps/libusb/meson.build:112:2: ERROR: Dependency "IOKit" not found, tried
framework

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/111635] Objects built with -flto cannot be linked with Xcode
  2023-09-29  0:16 [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode amy at amyspark dot me
                   ` (3 preceding siblings ...)
  2023-10-30 16:48 ` fxcoudert at gcc dot gnu.org
@ 2023-10-30 16:51 ` fxcoudert at gcc dot gnu.org
  2023-10-31  2:17 ` amy at amyspark dot me
  2023-10-31  3:08 ` amy at amyspark dot me
  6 siblings, 0 replies; 8+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2023-10-30 16:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111635

--- Comment #5 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
Third try (on aarch64-darwin): I installed Homebrew's libusb. But now, the
build succeeds…

⌁ [fx:/tmp/bmpflash] f87ad30 6s ± meson compile -C build
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /opt/homebrew/bin/ninja -C
/private/tmp/bmpflash/build
ninja: Entering directory `/private/tmp/bmpflash/build'
[27/27] Linking target src/bmpflash

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/111635] Objects built with -flto cannot be linked with Xcode
  2023-09-29  0:16 [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode amy at amyspark dot me
                   ` (4 preceding siblings ...)
  2023-10-30 16:51 ` fxcoudert at gcc dot gnu.org
@ 2023-10-31  2:17 ` amy at amyspark dot me
  2023-10-31  3:08 ` amy at amyspark dot me
  6 siblings, 0 replies; 8+ messages in thread
From: amy at amyspark dot me @ 2023-10-31  2:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111635

--- Comment #6 from Amyspark <amy at amyspark dot me> ---
I need to recover my GCC installation post Homebrew forcing an OS upgrade to
Monterey. Still, I think this needs to be tested against the x64 target -- I've
seen some issues only happening when targeting it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug target/111635] Objects built with -flto cannot be linked with Xcode
  2023-09-29  0:16 [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode amy at amyspark dot me
                   ` (5 preceding siblings ...)
  2023-10-31  2:17 ` amy at amyspark dot me
@ 2023-10-31  3:08 ` amy at amyspark dot me
  6 siblings, 0 replies; 8+ messages in thread
From: amy at amyspark dot me @ 2023-10-31  3:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111635

--- Comment #7 from Amyspark <amy at amyspark dot me> ---
I can confirm this is no longer reproducible with macOS Monterey 12.7, Xcode
14.2, and the following linker version:

@(#)PROGRAM:ld  PROJECT:ld64-820.1
BUILD 20:07:01 Nov  7 2022
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386
x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 14.0.0, (clang-1400.0.29.202) (static support
for 29, runtime is 29)
TAPI support using: Apple TAPI version 14.0.0 (tapi-1400.0.11)

As it looks like it was a AppleClang bug fixed in a newer Xcode version, I'd
suggest to close this. Thanks to everyone who triaged it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-31  3:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-29  0:16 [Bug lto/111635] New: Objects built with -flto cannot be linked with Xcode amy at amyspark dot me
2023-09-29  0:17 ` [Bug lto/111635] " amy at amyspark dot me
2023-09-29  0:27 ` [Bug target/111635] " pinskia at gcc dot gnu.org
2023-09-29  0:30 ` pinskia at gcc dot gnu.org
2023-10-30 16:48 ` fxcoudert at gcc dot gnu.org
2023-10-30 16:51 ` fxcoudert at gcc dot gnu.org
2023-10-31  2:17 ` amy at amyspark dot me
2023-10-31  3:08 ` amy at amyspark dot me

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).