On Fri, Feb 27, 2026 at 12:26 AM Torbjorn SVENSSON
<[email protected]> wrote:
>
> Hi,
>
> The toplevel-extended-asm-1 test added in this commit fails on arm-none-eabi:
>
> $ /build/r16-6691-g4faf70b615634e/bin/arm-none-eabi-gcc
> /build/gcc_src/gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_0.c -mthumb
> -march=armv6s-m -mtune=cortex-m0 -mfloat-abi=soft -mfpu=auto
> -fdiagnostics-plain-output -O2 -flto -flto-partition=1to1 -c -o
> c_lto_toplevel-extended-asm-1_0.o
> $ /build/r16-6691-g4faf70b615634e/bin/arm-none-eabi-gcc
> /build/gcc_src/gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_1.c -mthumb
> -march=armv6s-m -mtune=cortex-m0 -mfloat-abi=soft -mfpu=auto
> -fdiagnostics-plain-output -O2 -flto -flto-partition=1to1 -c -o
> c_lto_toplevel-extended-asm-1_1.o
> $ /build/r16-6691-g4faf70b615634e/bin/arm-none-eabi-gcc
> c_lto_toplevel-extended-asm-1_0.o c_lto_toplevel-extended-asm-1_1.o -mthumb
> -march=armv6s-m -mtune=cortex-m0 -mfloat-abi=soft -mfpu=auto -dumpbase ""
> -fdiagnostics-plain-output -O2 -flto -flto-partition=1to1
> --specs=rdimon.specs -o gcc-dg-lto-toplevel-extended-asm-1-01.exe
> lto-wrapper: warning: using serial compilation of 2 LTRANS jobs
> lto-wrapper: note: see the '-flto' option documentation for more information
> /build/r16-6691-g4faf70b615634e/arm-none-eabi/bin/ld:
> /tmp/ccQitC6K.ltrans0.ltrans.o(asm_fn_used): Unknown destination type
> (ARM/Thumb) in /tmp/ccQitC6K.ltrans1.ltrans.o
> /tmp/ccQitC6K.ltrans1.ltrans.o: in function `local_caller':
> <artificial>:(.text+0xa): dangerous relocation: unsupported relocation
> collect2: error: ld returned 1 exit status
>
> Is this test expected to only work for x86_64-pc-linux-gnu or something
> similar?
Looks like the issue is only for targets which have 2 "modes". In that
it will fail for arm and mips (with mips16).
Fixing the testcase for arm is doable I think but requires changing
the inline-asm for arm to have the correct markers for the function to
be always thumb (I think).
Maybe a new testcase for arm and disable this testcase for arm is
better. Either way it is just a testcase failure rather than a failure
of the patch.
Thanks,
Andrew
>
> Note, I get the same error on r16-7687-g772499fd7e2f9a.
>
> Kind regards,
> Torbjörn
>
> On 2025-12-19 22:44, Michal Jires wrote:
> > Change in v3:
> > Add safe_as_a<asm_node*> needed for rebase.
> >
> > ---
> >
> > Previous patch added asm_node streaming, so we need to add referenced
> > symbols to partition.
> >
> > asm_nodes must be added to partition before computing the boundary.
> >
> > gcc/ChangeLog:
> >
> > * lto-cgraph.cc (compute_ltrans_boundary): Add symbols
> > referenced from asm_nodes.
> > * lto-streamer-out.cc (lto_output): Move adding asm_nodes
> > to...
> > * passes.cc (ipa_write_summaries): ...here.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.dg/lto/toplevel-extended-asm-1_0.c: New test.
> > * gcc.dg/lto/toplevel-extended-asm-1_1.c: New test.
> > ---
> > gcc/lto-cgraph.cc | 18 ++++++++++++++++++
> > gcc/lto-streamer-out.cc | 9 ---------
> > gcc/passes.cc | 5 +++++
> > .../gcc.dg/lto/toplevel-extended-asm-1_0.c | 19 +++++++++++++++++++
> > .../gcc.dg/lto/toplevel-extended-asm-1_1.c | 12 ++++++++++++
> > 5 files changed, 54 insertions(+), 9 deletions(-)
> > create mode 100644 gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_0.c
> > create mode 100644 gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_1.c
> >
> > diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
> > index 3a705463f89..4c686c45bc6 100644
> > --- a/gcc/lto-cgraph.cc
> > +++ b/gcc/lto-cgraph.cc
> > @@ -899,6 +899,24 @@ compute_ltrans_boundary (lto_symtab_encoder_t
> > in_encoder)
> > lto_set_symtab_encoder_encode_initializer (encoder, vnode);
> > create_references (encoder, vnode);
> > }
> > + for (lsei = lsei_start (in_encoder); !lsei_end_p (lsei); lsei_next
> > (&lsei))
> > + {
> > + toplevel_node *tnode = lsei_node (lsei);
> > + if (asm_node* node = dyn_cast <asm_node*> (tnode))
> > + {
> > + symtab_node* ref;
> > + for (unsigned i = 0; node->symbols_referenced.iterate (i, &ref);
> > i++)
> > + {
> > + if (!lto_symtab_encoder_in_partition_p (encoder, ref))
> > + {
> > + if (cgraph_node* cref = dyn_cast <cgraph_node*> (ref))
> > + add_node_to (encoder, cref, false);
> > + else if (varpool_node *vref = dyn_cast <varpool_node *>
> > (ref))
> > + lto_symtab_encoder_encode (encoder, vref);
> > + }
> > + }
> > + }
> > + }
> > /* Pickle in also the initializer of all referenced readonly variables
> > to help folding. Constant pool variables are not shared, so we must
> > pickle those too. */
> > diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
> > index 1f7b81372c7..8036f0db12a 100644
> > --- a/gcc/lto-streamer-out.cc
> > +++ b/gcc/lto-streamer-out.cc
> > @@ -2817,15 +2817,6 @@ lto_output (void)
> > lto_symtab_encoder_t encoder = lto_get_out_decl_state
> > ()->symtab_node_encoder;
> > auto_vec<symtab_node *> symbols_to_copy;
> >
> > - if (!flag_wpa)
> > - {
> > - asm_node *anode;
> > - for (anode = symtab->first_asm_symbol ();
> > - anode;
> > - anode = safe_as_a<asm_node*>(anode->next))
> > - lto_set_symtab_encoder_in_partition (encoder, anode);
> > - }
> > -
> > create_order_remap (encoder);
> >
> > prune_offload_funcs ();
> > diff --git a/gcc/passes.cc b/gcc/passes.cc
> > index a33c8d924a5..c2068a195cf 100644
> > --- a/gcc/passes.cc
> > +++ b/gcc/passes.cc
> > @@ -2899,6 +2899,11 @@ ipa_write_summaries (void)
> > if (vnode->need_lto_streaming)
> > lto_set_symtab_encoder_in_partition (encoder, vnode);
> >
> > + asm_node *anode;
> > + for (anode = symtab->first_asm_symbol (); anode;
> > + anode = safe_as_a<asm_node*> (anode->next))
> > + lto_set_symtab_encoder_in_partition (encoder, anode);
> > +
> > ipa_write_summaries_1 (compute_ltrans_boundary (encoder),
> > flag_generate_offload);
> >
> > diff --git a/gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_0.c
> > b/gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_0.c
> > new file mode 100644
> > index 00000000000..341d95ae0d5
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_0.c
> > @@ -0,0 +1,19 @@
> > +/* { dg-lto-do link } */
> > +/* { dg-lto-options {{-O2 -flto -flto-partition=1to1} } } */
> > +
> > +void asm_fn();
> > +void asm_fn_used();
> > +
> > +asm(".global %cc0\n%cc0:" :: ":" (asm_fn));
> > +asm(".global %cc0\n%cc0:" :: ":" (asm_fn_used));
> > +
> > +
> > +__attribute__((noinline))
> > +int privatized_fn(int v) { return v + v;}
> > +
> > +extern void call_privatized_fn();
> > +
> > +int main() {
> > + privatized_fn (0);
> > + call_privatized_fn ();
> > +}
> > diff --git a/gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_1.c
> > b/gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_1.c
> > new file mode 100644
> > index 00000000000..0c665ffafcb
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/lto/toplevel-extended-asm-1_1.c
> > @@ -0,0 +1,12 @@
> > +extern void asm_fn_used();
> > +
> > +__attribute__((used))
> > +void local_caller() {
> > + asm_fn_used();
> > +}
> > +
> > +__attribute__((noipa))
> > +static void privatized_fn() { asm volatile ("");}
> > +asm(".long %cc0" :: "s"(privatized_fn));
> > +
> > +void call_privatized_fn() { privatized_fn();}
>