Remove fno-unit-at-a-time make variable

Message ID 20220330050729.2176630-1-maskray@google.com
State Dropped
Headers
Series Remove fno-unit-at-a-time make variable |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Fangrui Song March 30, 2022, 5:07 a.m. UTC
  795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
is a rough replacement for this legacy option
(https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).

The reordering requirement does not seem to be needed any longer.
---
 config.make.in        |  1 -
 configure             | 32 --------------------------------
 configure.ac          | 19 -------------------
 stdio-common/Makefile |  2 --
 4 files changed, 54 deletions(-)
  

Comments

Adhemerval Zanella Netto March 30, 2022, 12:46 p.m. UTC | #1
On 30/03/2022 02:07, Fangrui Song wrote:
> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
> is a rough replacement for this legacy option
> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
> 
> The reordering requirement does not seem to be needed any longer.

We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
does not create _sys_errlist and _sys_siglist with expected sizes defined by
glibc ABI.

I am trying to fix without resorting to compiler options.

> ---
>  config.make.in        |  1 -
>  configure             | 32 --------------------------------
>  configure.ac          | 19 -------------------
>  stdio-common/Makefile |  2 --
>  4 files changed, 54 deletions(-)
> 
> diff --git a/config.make.in b/config.make.in
> index 6d43e691f7..ecde84a7da 100644
> --- a/config.make.in
> +++ b/config.make.in
> @@ -69,7 +69,6 @@ have-selinux = @have_selinux@
>  have-libaudit = @have_libaudit@
>  have-libcap = @have_libcap@
>  have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
> -fno-unit-at-a-time = @fno_unit_at_a_time@
>  bind-now = @bindnow@
>  have-hash-style = @libc_cv_hashstyle@
>  use-default-link = @use_default_link@
> diff --git a/configure b/configure
> index 2a3cb49b0b..f836874a58 100755
> --- a/configure
> +++ b/configure
> @@ -620,7 +620,6 @@ libc_cv_cc_loop_to_function
>  libc_cv_cc_submachine
>  libc_cv_cc_nofma
>  libc_cv_mtls_dialect_gnu2
> -fno_unit_at_a_time
>  libc_cv_has_glob_dat
>  libc_cv_hashstyle
>  libc_cv_fpie
> @@ -6319,37 +6318,6 @@ fi
>  $as_echo "$libc_cv_has_glob_dat" >&6; }
>  
>  
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-toplevel-reorder -fno-section-anchors" >&5
> -$as_echo_n "checking for -fno-toplevel-reorder -fno-section-anchors... " >&6; }
> -if ${libc_cv_fno_toplevel_reorder+:} false; then :
> -  $as_echo_n "(cached) " >&6
> -else
> -  cat > conftest.c <<EOF
> -int foo;
> -EOF
> -if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -S -fno-toplevel-reorder -fno-section-anchors
> -			    conftest.c 1>&5'
> -  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
> -  (eval $ac_try) 2>&5
> -  ac_status=$?
> -  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
> -  test $ac_status = 0; }; }
> -then
> -  libc_cv_fno_toplevel_reorder=yes
> -else
> -  libc_cv_fno_toplevel_reorder=no
> -fi
> -rm -f conftest*
> -fi
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_fno_toplevel_reorder" >&5
> -$as_echo "$libc_cv_fno_toplevel_reorder" >&6; }
> -if test $libc_cv_fno_toplevel_reorder = yes; then
> -  fno_unit_at_a_time="-fno-toplevel-reorder -fno-section-anchors"
> -else
> -  fno_unit_at_a_time=-fno-unit-at-a-time
> -fi
> -
> -
>  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -mtls-dialect=gnu2" >&5
>  $as_echo_n "checking for -mtls-dialect=gnu2... " >&6; }
>  if ${libc_cv_mtls_dialect_gnu2+:} false; then :
> diff --git a/configure.ac b/configure.ac
> index fa7d3c025b..ec1db36d46 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1478,25 +1478,6 @@ fi
>  rm -f conftest*])
>  AC_SUBST(libc_cv_has_glob_dat)
>  
> -AC_CACHE_CHECK(for -fno-toplevel-reorder -fno-section-anchors, libc_cv_fno_toplevel_reorder, [dnl
> -cat > conftest.c <<EOF
> -int foo;
> -EOF
> -if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -S -fno-toplevel-reorder -fno-section-anchors
> -			    conftest.c 1>&AS_MESSAGE_LOG_FD])
> -then
> -  libc_cv_fno_toplevel_reorder=yes
> -else
> -  libc_cv_fno_toplevel_reorder=no
> -fi
> -rm -f conftest*])
> -if test $libc_cv_fno_toplevel_reorder = yes; then
> -  fno_unit_at_a_time="-fno-toplevel-reorder -fno-section-anchors"
> -else
> -  fno_unit_at_a_time=-fno-unit-at-a-time
> -fi
> -AC_SUBST(fno_unit_at_a_time)
> -
>  AC_CACHE_CHECK([for -mtls-dialect=gnu2], libc_cv_mtls_dialect_gnu2,
>  [dnl
>  cat > conftest.c <<EOF
> diff --git a/stdio-common/Makefile b/stdio-common/Makefile
> index 435cd8904f..dbaecbd76e 100644
> --- a/stdio-common/Makefile
> +++ b/stdio-common/Makefile
> @@ -333,8 +333,6 @@ CFLAGS-isoc99_vfscanf.c += -fexceptions
>  CFLAGS-isoc99_vscanf.c += -fexceptions
>  CFLAGS-isoc99_fscanf.c += -fexceptions
>  CFLAGS-isoc99_scanf.c += -fexceptions
> -CFLAGS-errlist.c += $(fno-unit-at-a-time)
> -CFLAGS-siglist.c += $(fno-unit-at-a-time)
>  
>  # scanf14a.c and scanf16a.c test a deprecated extension which is no
>  # longer visible under most conformance levels; see the source files
  
Fangrui Song March 30, 2022, 4:23 p.m. UTC | #2
On 2022-03-30, Adhemerval Zanella wrote:
>
>
>On 30/03/2022 02:07, Fangrui Song wrote:
>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>> is a rough replacement for this legacy option
>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>
>> The reordering requirement does not seem to be needed any longer.
>
>We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>does not create _sys_errlist and _sys_siglist with expected sizes defined by
>glibc ABI.
>
>I am trying to fix without resorting to compiler options.

DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:


        .globl  __GLIBC_2_1_sys_errlist
.set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
         .type   __GLIBC_2_1_sys_errlist,@object
         .size   __GLIBC_2_1_sys_errlist, 1000
         .globl  __GLIBC_2_1__sys_errlist
.set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
         .type   __GLIBC_2_1__sys_errlist,@object
         .size   __GLIBC_2_1__sys_errlist, 1000
.symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
.symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
.symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
.symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
         .globl  __GLIBC_2_3_sys_errlist
.set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
         .type   __GLIBC_2_3_sys_errlist,@object
         .size   __GLIBC_2_3_sys_errlist, 1008
         .globl  __GLIBC_2_3__sys_errlist
.set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
         .type   __GLIBC_2_3__sys_errlist,@object
         .size   __GLIBC_2_3__sys_errlist, 1008
.symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
.symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
.symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
.symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
         .globl  __GLIBC_2_4_sys_errlist

I do not know whether GCC would reorder these macros. Even yes,
that'd just change the .symtab entries in the relocatable object file.
The linker behavior remains the same with reordering.

>> ---
>>  config.make.in        |  1 -
>>  configure             | 32 --------------------------------
>>  configure.ac          | 19 -------------------
>>  stdio-common/Makefile |  2 --
>>  4 files changed, 54 deletions(-)
>>
>> diff --git a/config.make.in b/config.make.in
>> index 6d43e691f7..ecde84a7da 100644
>> --- a/config.make.in
>> +++ b/config.make.in
>> @@ -69,7 +69,6 @@ have-selinux = @have_selinux@
>>  have-libaudit = @have_libaudit@
>>  have-libcap = @have_libcap@
>>  have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
>> -fno-unit-at-a-time = @fno_unit_at_a_time@
>>  bind-now = @bindnow@
>>  have-hash-style = @libc_cv_hashstyle@
>>  use-default-link = @use_default_link@
>> diff --git a/configure b/configure
>> index 2a3cb49b0b..f836874a58 100755
>> --- a/configure
>> +++ b/configure
>> @@ -620,7 +620,6 @@ libc_cv_cc_loop_to_function
>>  libc_cv_cc_submachine
>>  libc_cv_cc_nofma
>>  libc_cv_mtls_dialect_gnu2
>> -fno_unit_at_a_time
>>  libc_cv_has_glob_dat
>>  libc_cv_hashstyle
>>  libc_cv_fpie
>> @@ -6319,37 +6318,6 @@ fi
>>  $as_echo "$libc_cv_has_glob_dat" >&6; }
>>
>>
>> -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-toplevel-reorder -fno-section-anchors" >&5
>> -$as_echo_n "checking for -fno-toplevel-reorder -fno-section-anchors... " >&6; }
>> -if ${libc_cv_fno_toplevel_reorder+:} false; then :
>> -  $as_echo_n "(cached) " >&6
>> -else
>> -  cat > conftest.c <<EOF
>> -int foo;
>> -EOF
>> -if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -S -fno-toplevel-reorder -fno-section-anchors
>> -			    conftest.c 1>&5'
>> -  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>> -  (eval $ac_try) 2>&5
>> -  ac_status=$?
>> -  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>> -  test $ac_status = 0; }; }
>> -then
>> -  libc_cv_fno_toplevel_reorder=yes
>> -else
>> -  libc_cv_fno_toplevel_reorder=no
>> -fi
>> -rm -f conftest*
>> -fi
>> -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_fno_toplevel_reorder" >&5
>> -$as_echo "$libc_cv_fno_toplevel_reorder" >&6; }
>> -if test $libc_cv_fno_toplevel_reorder = yes; then
>> -  fno_unit_at_a_time="-fno-toplevel-reorder -fno-section-anchors"
>> -else
>> -  fno_unit_at_a_time=-fno-unit-at-a-time
>> -fi
>> -
>> -
>>  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -mtls-dialect=gnu2" >&5
>>  $as_echo_n "checking for -mtls-dialect=gnu2... " >&6; }
>>  if ${libc_cv_mtls_dialect_gnu2+:} false; then :
>> diff --git a/configure.ac b/configure.ac
>> index fa7d3c025b..ec1db36d46 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -1478,25 +1478,6 @@ fi
>>  rm -f conftest*])
>>  AC_SUBST(libc_cv_has_glob_dat)
>>
>> -AC_CACHE_CHECK(for -fno-toplevel-reorder -fno-section-anchors, libc_cv_fno_toplevel_reorder, [dnl
>> -cat > conftest.c <<EOF
>> -int foo;
>> -EOF
>> -if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -S -fno-toplevel-reorder -fno-section-anchors
>> -			    conftest.c 1>&AS_MESSAGE_LOG_FD])
>> -then
>> -  libc_cv_fno_toplevel_reorder=yes
>> -else
>> -  libc_cv_fno_toplevel_reorder=no
>> -fi
>> -rm -f conftest*])
>> -if test $libc_cv_fno_toplevel_reorder = yes; then
>> -  fno_unit_at_a_time="-fno-toplevel-reorder -fno-section-anchors"
>> -else
>> -  fno_unit_at_a_time=-fno-unit-at-a-time
>> -fi
>> -AC_SUBST(fno_unit_at_a_time)
>> -
>>  AC_CACHE_CHECK([for -mtls-dialect=gnu2], libc_cv_mtls_dialect_gnu2,
>>  [dnl
>>  cat > conftest.c <<EOF
>> diff --git a/stdio-common/Makefile b/stdio-common/Makefile
>> index 435cd8904f..dbaecbd76e 100644
>> --- a/stdio-common/Makefile
>> +++ b/stdio-common/Makefile
>> @@ -333,8 +333,6 @@ CFLAGS-isoc99_vfscanf.c += -fexceptions
>>  CFLAGS-isoc99_vscanf.c += -fexceptions
>>  CFLAGS-isoc99_fscanf.c += -fexceptions
>>  CFLAGS-isoc99_scanf.c += -fexceptions
>> -CFLAGS-errlist.c += $(fno-unit-at-a-time)
>> -CFLAGS-siglist.c += $(fno-unit-at-a-time)
>>
>>  # scanf14a.c and scanf16a.c test a deprecated extension which is no
>>  # longer visible under most conformance levels; see the source files
  
Adhemerval Zanella Netto March 30, 2022, 4:28 p.m. UTC | #3
On 30/03/2022 13:23, Fangrui Song wrote:
> On 2022-03-30, Adhemerval Zanella wrote:
>>
>>
>> On 30/03/2022 02:07, Fangrui Song wrote:
>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>>> is a rough replacement for this legacy option
>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>>
>>> The reordering requirement does not seem to be needed any longer.
>>
>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
>> glibc ABI.
>>
>> I am trying to fix without resorting to compiler options.
> 
> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
> 
> 
>        .globl  __GLIBC_2_1_sys_errlist
> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
>         .type   __GLIBC_2_1_sys_errlist,@object
>         .size   __GLIBC_2_1_sys_errlist, 1000
>         .globl  __GLIBC_2_1__sys_errlist
> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
>         .type   __GLIBC_2_1__sys_errlist,@object
>         .size   __GLIBC_2_1__sys_errlist, 1000
> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
>         .globl  __GLIBC_2_3_sys_errlist
> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
>         .type   __GLIBC_2_3_sys_errlist,@object
>         .size   __GLIBC_2_3_sys_errlist, 1008
>         .globl  __GLIBC_2_3__sys_errlist
> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
>         .type   __GLIBC_2_3__sys_errlist,@object
>         .size   __GLIBC_2_3__sys_errlist, 1008
> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
>         .globl  __GLIBC_2_4_sys_errlist
> 
> I do not know whether GCC would reorder these macros. Even yes,
> that'd just change the .symtab entries in the relocatable object file.
> The linker behavior remains the same with reordering.

It does not seem to, just remove the -fno-unit-at-a-time and issue make
check-abi and you will see that object size for the compat symbols 
reference to _sys_err_internal instead of the define compat ones.
  
Fangrui Song March 31, 2022, 3:43 a.m. UTC | #4
On 2022-03-30, Adhemerval Zanella wrote:
>
>
>On 30/03/2022 13:23, Fangrui Song wrote:
>> On 2022-03-30, Adhemerval Zanella wrote:
>>>
>>>
>>> On 30/03/2022 02:07, Fangrui Song wrote:
>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>>>> is a rough replacement for this legacy option
>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>>>
>>>> The reordering requirement does not seem to be needed any longer.
>>>
>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
>>> glibc ABI.
>>>
>>> I am trying to fix without resorting to compiler options.
>>
>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
>>
>>
>>        .globl  __GLIBC_2_1_sys_errlist
>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
>>         .type   __GLIBC_2_1_sys_errlist,@object
>>         .size   __GLIBC_2_1_sys_errlist, 1000
>>         .globl  __GLIBC_2_1__sys_errlist
>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
>>         .type   __GLIBC_2_1__sys_errlist,@object
>>         .size   __GLIBC_2_1__sys_errlist, 1000
>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
>>         .globl  __GLIBC_2_3_sys_errlist
>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
>>         .type   __GLIBC_2_3_sys_errlist,@object
>>         .size   __GLIBC_2_3_sys_errlist, 1008
>>         .globl  __GLIBC_2_3__sys_errlist
>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
>>         .type   __GLIBC_2_3__sys_errlist,@object
>>         .size   __GLIBC_2_3__sys_errlist, 1008
>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
>>         .globl  __GLIBC_2_4_sys_errlist
>>
>> I do not know whether GCC would reorder these macros. Even yes,
>> that'd just change the .symtab entries in the relocatable object file.
>> The linker behavior remains the same with reordering.
>
>It does not seem to, just remove the -fno-unit-at-a-time and issue make
>check-abi and you will see that object size for the compat symbols
>reference to _sys_err_internal instead of the define compat ones.

I see. I think this is a brittle behavior in GNU assembler. Filed
https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
information. I have created a patch but I know that will not solve
glibc's problem :(
  
Adhemerval Zanella Netto March 31, 2022, 11:33 a.m. UTC | #5
On 31/03/2022 00:43, Fangrui Song wrote:
> On 2022-03-30, Adhemerval Zanella wrote:
>>
>>
>> On 30/03/2022 13:23, Fangrui Song wrote:
>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>
>>>>
>>>> On 30/03/2022 02:07, Fangrui Song wrote:
>>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>>>>> is a rough replacement for this legacy option
>>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>>>>
>>>>> The reordering requirement does not seem to be needed any longer.
>>>>
>>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
>>>> glibc ABI.
>>>>
>>>> I am trying to fix without resorting to compiler options.
>>>
>>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
>>>
>>>
>>>        .globl  __GLIBC_2_1_sys_errlist
>>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
>>>         .type   __GLIBC_2_1_sys_errlist,@object
>>>         .size   __GLIBC_2_1_sys_errlist, 1000
>>>         .globl  __GLIBC_2_1__sys_errlist
>>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
>>>         .type   __GLIBC_2_1__sys_errlist,@object
>>>         .size   __GLIBC_2_1__sys_errlist, 1000
>>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
>>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
>>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
>>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
>>>         .globl  __GLIBC_2_3_sys_errlist
>>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
>>>         .type   __GLIBC_2_3_sys_errlist,@object
>>>         .size   __GLIBC_2_3_sys_errlist, 1008
>>>         .globl  __GLIBC_2_3__sys_errlist
>>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
>>>         .type   __GLIBC_2_3__sys_errlist,@object
>>>         .size   __GLIBC_2_3__sys_errlist, 1008
>>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
>>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
>>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
>>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
>>>         .globl  __GLIBC_2_4_sys_errlist
>>>
>>> I do not know whether GCC would reorder these macros. Even yes,
>>> that'd just change the .symtab entries in the relocatable object file.
>>> The linker behavior remains the same with reordering.
>>
>> It does not seem to, just remove the -fno-unit-at-a-time and issue make
>> check-abi and you will see that object size for the compat symbols
>> reference to _sys_err_internal instead of the define compat ones.
> 
> I see. I think this is a brittle behavior in GNU assembler. Filed
> https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
> information. I have created a patch but I know that will not solve
> glibc's problem :(

It would be good to have this fixes, but unfortunately we need a way
to handle this on older binutils.  I am kind worried that the only
possible way to actually fix this without resorting to any compiler 
flags is coding the array definitions in assembly direct...
  
Fangrui Song April 4, 2022, 3:57 p.m. UTC | #6
On 2022-03-31, Adhemerval Zanella wrote:
>
>
>On 31/03/2022 00:43, Fangrui Song wrote:
>> On 2022-03-30, Adhemerval Zanella wrote:
>>>
>>>
>>> On 30/03/2022 13:23, Fangrui Song wrote:
>>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>>
>>>>>
>>>>> On 30/03/2022 02:07, Fangrui Song wrote:
>>>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>>>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>>>>>> is a rough replacement for this legacy option
>>>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>>>>>
>>>>>> The reordering requirement does not seem to be needed any longer.
>>>>>
>>>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>>>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
>>>>> glibc ABI.
>>>>>
>>>>> I am trying to fix without resorting to compiler options.
>>>>
>>>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
>>>>
>>>>
>>>>        .globl  __GLIBC_2_1_sys_errlist
>>>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
>>>>         .type   __GLIBC_2_1_sys_errlist,@object
>>>>         .size   __GLIBC_2_1_sys_errlist, 1000
>>>>         .globl  __GLIBC_2_1__sys_errlist
>>>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
>>>>         .type   __GLIBC_2_1__sys_errlist,@object
>>>>         .size   __GLIBC_2_1__sys_errlist, 1000
>>>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
>>>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
>>>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
>>>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
>>>>         .globl  __GLIBC_2_3_sys_errlist
>>>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
>>>>         .type   __GLIBC_2_3_sys_errlist,@object
>>>>         .size   __GLIBC_2_3_sys_errlist, 1008
>>>>         .globl  __GLIBC_2_3__sys_errlist
>>>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
>>>>         .type   __GLIBC_2_3__sys_errlist,@object
>>>>         .size   __GLIBC_2_3__sys_errlist, 1008
>>>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
>>>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
>>>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
>>>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
>>>>         .globl  __GLIBC_2_4_sys_errlist
>>>>
>>>> I do not know whether GCC would reorder these macros. Even yes,
>>>> that'd just change the .symtab entries in the relocatable object file.
>>>> The linker behavior remains the same with reordering.
>>>
>>> It does not seem to, just remove the -fno-unit-at-a-time and issue make
>>> check-abi and you will see that object size for the compat symbols
>>> reference to _sys_err_internal instead of the define compat ones.
>>
>> I see. I think this is a brittle behavior in GNU assembler. Filed
>> https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
>> information. I have created a patch but I know that will not solve
>> glibc's problem :(
>
>It would be good to have this fixes, but unfortunately we need a way
>to handle this on older binutils.  I am kind worried that the only
>possible way to actually fix this without resorting to any compiler
>flags is coding the array definitions in assembly direct...

The GNU assembler issue has been fixed https://sourceware.org/bugzilla/show_bug.cgi?id=29012
(milestone 2.39, way larger than the current required version: 2.25)

Switching to assembly output doesn't seem bad :-)

If you keep the compiler driver option but need to refactor the nearby
code, you may drop -fno-unit-at-a-time. It was added in 2006 (somewhere
between GCC 4.1 and 4.4), while glibc requires GCC>=6.2.
  
Adhemerval Zanella Netto April 5, 2022, 2:35 p.m. UTC | #7
On 04/04/2022 12:57, Fangrui Song wrote:
> 
> On 2022-03-31, Adhemerval Zanella wrote:
>>
>>
>> On 31/03/2022 00:43, Fangrui Song wrote:
>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>
>>>>
>>>> On 30/03/2022 13:23, Fangrui Song wrote:
>>>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>>>
>>>>>>
>>>>>> On 30/03/2022 02:07, Fangrui Song wrote:
>>>>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>>>>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>>>>>>> is a rough replacement for this legacy option
>>>>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>>>>>>
>>>>>>> The reordering requirement does not seem to be needed any longer.
>>>>>>
>>>>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>>>>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
>>>>>> glibc ABI.
>>>>>>
>>>>>> I am trying to fix without resorting to compiler options.
>>>>>
>>>>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
>>>>>
>>>>>
>>>>>        .globl  __GLIBC_2_1_sys_errlist
>>>>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
>>>>>         .type   __GLIBC_2_1_sys_errlist,@object
>>>>>         .size   __GLIBC_2_1_sys_errlist, 1000
>>>>>         .globl  __GLIBC_2_1__sys_errlist
>>>>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
>>>>>         .type   __GLIBC_2_1__sys_errlist,@object
>>>>>         .size   __GLIBC_2_1__sys_errlist, 1000
>>>>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
>>>>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
>>>>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
>>>>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
>>>>>         .globl  __GLIBC_2_3_sys_errlist
>>>>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
>>>>>         .type   __GLIBC_2_3_sys_errlist,@object
>>>>>         .size   __GLIBC_2_3_sys_errlist, 1008
>>>>>         .globl  __GLIBC_2_3__sys_errlist
>>>>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
>>>>>         .type   __GLIBC_2_3__sys_errlist,@object
>>>>>         .size   __GLIBC_2_3__sys_errlist, 1008
>>>>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
>>>>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
>>>>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
>>>>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
>>>>>         .globl  __GLIBC_2_4_sys_errlist
>>>>>
>>>>> I do not know whether GCC would reorder these macros. Even yes,
>>>>> that'd just change the .symtab entries in the relocatable object file.
>>>>> The linker behavior remains the same with reordering.
>>>>
>>>> It does not seem to, just remove the -fno-unit-at-a-time and issue make
>>>> check-abi and you will see that object size for the compat symbols
>>>> reference to _sys_err_internal instead of the define compat ones.
>>>
>>> I see. I think this is a brittle behavior in GNU assembler. Filed
>>> https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
>>> information. I have created a patch but I know that will not solve
>>> glibc's problem :(
>>
>> It would be good to have this fixes, but unfortunately we need a way
>> to handle this on older binutils.  I am kind worried that the only
>> possible way to actually fix this without resorting to any compiler
>> flags is coding the array definitions in assembly direct...
> 
> The GNU assembler issue has been fixed https://sourceware.org/bugzilla/show_bug.cgi?id=29012
> (milestone 2.39, way larger than the current required version: 2.25)
> 
> Switching to assembly output doesn't seem bad :-)
> 
> If you keep the compiler driver option but need to refactor the nearby
> code, you may drop -fno-unit-at-a-time. It was added in 2006 (somewhere
> between GCC 4.1 and 4.4), while glibc requires GCC>=6.2.

Good to know we won't need to rely on compiler flags to get the expected
correct asm directives. I am still struggling to get a fix without resorting
to compiler flags, but without much success.  Trying to move it to assembly
might be tricky, I am not sure if the data directives would be architecture
agnostic.
  
Fangrui Song April 5, 2022, 4:22 p.m. UTC | #8
On Tue, Apr 5, 2022 at 8:35 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 04/04/2022 12:57, Fangrui Song wrote:
> >
> > On 2022-03-31, Adhemerval Zanella wrote:
> >>
> >>
> >> On 31/03/2022 00:43, Fangrui Song wrote:
> >>> On 2022-03-30, Adhemerval Zanella wrote:
> >>>>
> >>>>
> >>>> On 30/03/2022 13:23, Fangrui Song wrote:
> >>>>> On 2022-03-30, Adhemerval Zanella wrote:
> >>>>>>
> >>>>>>
> >>>>>> On 30/03/2022 02:07, Fangrui Song wrote:
> >>>>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
> >>>>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
> >>>>>>> is a rough replacement for this legacy option
> >>>>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
> >>>>>>>
> >>>>>>> The reordering requirement does not seem to be needed any longer.
> >>>>>>
> >>>>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
> >>>>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
> >>>>>> glibc ABI.
> >>>>>>
> >>>>>> I am trying to fix without resorting to compiler options.
> >>>>>
> >>>>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
> >>>>>
> >>>>>
> >>>>>        .globl  __GLIBC_2_1_sys_errlist
> >>>>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
> >>>>>         .type   __GLIBC_2_1_sys_errlist,@object
> >>>>>         .size   __GLIBC_2_1_sys_errlist, 1000
> >>>>>         .globl  __GLIBC_2_1__sys_errlist
> >>>>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
> >>>>>         .type   __GLIBC_2_1__sys_errlist,@object
> >>>>>         .size   __GLIBC_2_1__sys_errlist, 1000
> >>>>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
> >>>>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
> >>>>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
> >>>>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
> >>>>>         .globl  __GLIBC_2_3_sys_errlist
> >>>>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
> >>>>>         .type   __GLIBC_2_3_sys_errlist,@object
> >>>>>         .size   __GLIBC_2_3_sys_errlist, 1008
> >>>>>         .globl  __GLIBC_2_3__sys_errlist
> >>>>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
> >>>>>         .type   __GLIBC_2_3__sys_errlist,@object
> >>>>>         .size   __GLIBC_2_3__sys_errlist, 1008
> >>>>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
> >>>>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
> >>>>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
> >>>>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
> >>>>>         .globl  __GLIBC_2_4_sys_errlist
> >>>>>
> >>>>> I do not know whether GCC would reorder these macros. Even yes,
> >>>>> that'd just change the .symtab entries in the relocatable object file.
> >>>>> The linker behavior remains the same with reordering.
> >>>>
> >>>> It does not seem to, just remove the -fno-unit-at-a-time and issue make
> >>>> check-abi and you will see that object size for the compat symbols
> >>>> reference to _sys_err_internal instead of the define compat ones.
> >>>
> >>> I see. I think this is a brittle behavior in GNU assembler. Filed
> >>> https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
> >>> information. I have created a patch but I know that will not solve
> >>> glibc's problem :(
> >>
> >> It would be good to have this fixes, but unfortunately we need a way
> >> to handle this on older binutils.  I am kind worried that the only
> >> possible way to actually fix this without resorting to any compiler
> >> flags is coding the array definitions in assembly direct...
> >
> > The GNU assembler issue has been fixed https://sourceware.org/bugzilla/show_bug.cgi?id=29012
> > (milestone 2.39, way larger than the current required version: 2.25)
> >
> > Switching to assembly output doesn't seem bad :-)
> >
> > If you keep the compiler driver option but need to refactor the nearby
> > code, you may drop -fno-unit-at-a-time. It was added in 2006 (somewhere
> > between GCC 4.1 and 4.4), while glibc requires GCC>=6.2.
>
> Good to know we won't need to rely on compiler flags to get the expected
> correct asm directives. I am still struggling to get a fix without resorting
> to compiler flags, but without much success.  Trying to move it to assembly
> might be tricky, I am not sure if the data directives would be architecture
> agnostic.

Many directives are architecture-independent:
https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops
binutils-gdb/gas/read.c:346 The `portable[]` array.

To support Clang, no refactoring is probably needed: just change
fno_unit_at_a_time to only specify -fno-toplevel-reorder (and rename
it), not th legacy -fno-unit-at-a-time.
  
Adhemerval Zanella Netto April 5, 2022, 4:40 p.m. UTC | #9
On 05/04/2022 13:22, Fāng-ruì Sòng wrote:
> On Tue, Apr 5, 2022 at 8:35 AM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>>
>>
>> On 04/04/2022 12:57, Fangrui Song wrote:
>>>
>>> On 2022-03-31, Adhemerval Zanella wrote:
>>>>
>>>>
>>>> On 31/03/2022 00:43, Fangrui Song wrote:
>>>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>>>
>>>>>>
>>>>>> On 30/03/2022 13:23, Fangrui Song wrote:
>>>>>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> On 30/03/2022 02:07, Fangrui Song wrote:
>>>>>>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>>>>>>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>>>>>>>>> is a rough replacement for this legacy option
>>>>>>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>>>>>>>>
>>>>>>>>> The reordering requirement does not seem to be needed any longer.
>>>>>>>>
>>>>>>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>>>>>>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
>>>>>>>> glibc ABI.
>>>>>>>>
>>>>>>>> I am trying to fix without resorting to compiler options.
>>>>>>>
>>>>>>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
>>>>>>>
>>>>>>>
>>>>>>>        .globl  __GLIBC_2_1_sys_errlist
>>>>>>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
>>>>>>>         .type   __GLIBC_2_1_sys_errlist,@object
>>>>>>>         .size   __GLIBC_2_1_sys_errlist, 1000
>>>>>>>         .globl  __GLIBC_2_1__sys_errlist
>>>>>>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
>>>>>>>         .type   __GLIBC_2_1__sys_errlist,@object
>>>>>>>         .size   __GLIBC_2_1__sys_errlist, 1000
>>>>>>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
>>>>>>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
>>>>>>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
>>>>>>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
>>>>>>>         .globl  __GLIBC_2_3_sys_errlist
>>>>>>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
>>>>>>>         .type   __GLIBC_2_3_sys_errlist,@object
>>>>>>>         .size   __GLIBC_2_3_sys_errlist, 1008
>>>>>>>         .globl  __GLIBC_2_3__sys_errlist
>>>>>>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
>>>>>>>         .type   __GLIBC_2_3__sys_errlist,@object
>>>>>>>         .size   __GLIBC_2_3__sys_errlist, 1008
>>>>>>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
>>>>>>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
>>>>>>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
>>>>>>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
>>>>>>>         .globl  __GLIBC_2_4_sys_errlist
>>>>>>>
>>>>>>> I do not know whether GCC would reorder these macros. Even yes,
>>>>>>> that'd just change the .symtab entries in the relocatable object file.
>>>>>>> The linker behavior remains the same with reordering.
>>>>>>
>>>>>> It does not seem to, just remove the -fno-unit-at-a-time and issue make
>>>>>> check-abi and you will see that object size for the compat symbols
>>>>>> reference to _sys_err_internal instead of the define compat ones.
>>>>>
>>>>> I see. I think this is a brittle behavior in GNU assembler. Filed
>>>>> https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
>>>>> information. I have created a patch but I know that will not solve
>>>>> glibc's problem :(
>>>>
>>>> It would be good to have this fixes, but unfortunately we need a way
>>>> to handle this on older binutils.  I am kind worried that the only
>>>> possible way to actually fix this without resorting to any compiler
>>>> flags is coding the array definitions in assembly direct...
>>>
>>> The GNU assembler issue has been fixed https://sourceware.org/bugzilla/show_bug.cgi?id=29012
>>> (milestone 2.39, way larger than the current required version: 2.25)
>>>
>>> Switching to assembly output doesn't seem bad :-)
>>>
>>> If you keep the compiler driver option but need to refactor the nearby
>>> code, you may drop -fno-unit-at-a-time. It was added in 2006 (somewhere
>>> between GCC 4.1 and 4.4), while glibc requires GCC>=6.2.
>>
>> Good to know we won't need to rely on compiler flags to get the expected
>> correct asm directives. I am still struggling to get a fix without resorting
>> to compiler flags, but without much success.  Trying to move it to assembly
>> might be tricky, I am not sure if the data directives would be architecture
>> agnostic.
> 
> Many directives are architecture-independent:
> https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops
> binutils-gdb/gas/read.c:346 The `portable[]` array.

I think we can make it work with asciz directive.

> 
> To support Clang, no refactoring is probably needed: just change
> fno_unit_at_a_time to only specify -fno-toplevel-reorder (and rename
> it), not th legacy -fno-unit-at-a-time.

Afaik llvm does not support -fno-toplevel-reorder
  
Fangrui Song April 5, 2022, 4:44 p.m. UTC | #10
On Tue, Apr 5, 2022 at 10:40 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 05/04/2022 13:22, Fāng-ruì Sòng wrote:
> > On Tue, Apr 5, 2022 at 8:35 AM Adhemerval Zanella
> > <adhemerval.zanella@linaro.org> wrote:
> >>
> >>
> >>
> >> On 04/04/2022 12:57, Fangrui Song wrote:
> >>>
> >>> On 2022-03-31, Adhemerval Zanella wrote:
> >>>>
> >>>>
> >>>> On 31/03/2022 00:43, Fangrui Song wrote:
> >>>>> On 2022-03-30, Adhemerval Zanella wrote:
> >>>>>>
> >>>>>>
> >>>>>> On 30/03/2022 13:23, Fangrui Song wrote:
> >>>>>>> On 2022-03-30, Adhemerval Zanella wrote:
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> On 30/03/2022 02:07, Fangrui Song wrote:
> >>>>>>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
> >>>>>>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
> >>>>>>>>> is a rough replacement for this legacy option
> >>>>>>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
> >>>>>>>>>
> >>>>>>>>> The reordering requirement does not seem to be needed any longer.
> >>>>>>>>
> >>>>>>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
> >>>>>>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
> >>>>>>>> glibc ABI.
> >>>>>>>>
> >>>>>>>> I am trying to fix without resorting to compiler options.
> >>>>>>>
> >>>>>>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
> >>>>>>>
> >>>>>>>
> >>>>>>>        .globl  __GLIBC_2_1_sys_errlist
> >>>>>>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
> >>>>>>>         .type   __GLIBC_2_1_sys_errlist,@object
> >>>>>>>         .size   __GLIBC_2_1_sys_errlist, 1000
> >>>>>>>         .globl  __GLIBC_2_1__sys_errlist
> >>>>>>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
> >>>>>>>         .type   __GLIBC_2_1__sys_errlist,@object
> >>>>>>>         .size   __GLIBC_2_1__sys_errlist, 1000
> >>>>>>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
> >>>>>>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
> >>>>>>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
> >>>>>>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
> >>>>>>>         .globl  __GLIBC_2_3_sys_errlist
> >>>>>>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
> >>>>>>>         .type   __GLIBC_2_3_sys_errlist,@object
> >>>>>>>         .size   __GLIBC_2_3_sys_errlist, 1008
> >>>>>>>         .globl  __GLIBC_2_3__sys_errlist
> >>>>>>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
> >>>>>>>         .type   __GLIBC_2_3__sys_errlist,@object
> >>>>>>>         .size   __GLIBC_2_3__sys_errlist, 1008
> >>>>>>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
> >>>>>>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
> >>>>>>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
> >>>>>>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
> >>>>>>>         .globl  __GLIBC_2_4_sys_errlist
> >>>>>>>
> >>>>>>> I do not know whether GCC would reorder these macros. Even yes,
> >>>>>>> that'd just change the .symtab entries in the relocatable object file.
> >>>>>>> The linker behavior remains the same with reordering.
> >>>>>>
> >>>>>> It does not seem to, just remove the -fno-unit-at-a-time and issue make
> >>>>>> check-abi and you will see that object size for the compat symbols
> >>>>>> reference to _sys_err_internal instead of the define compat ones.
> >>>>>
> >>>>> I see. I think this is a brittle behavior in GNU assembler. Filed
> >>>>> https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
> >>>>> information. I have created a patch but I know that will not solve
> >>>>> glibc's problem :(
> >>>>
> >>>> It would be good to have this fixes, but unfortunately we need a way
> >>>> to handle this on older binutils.  I am kind worried that the only
> >>>> possible way to actually fix this without resorting to any compiler
> >>>> flags is coding the array definitions in assembly direct...
> >>>
> >>> The GNU assembler issue has been fixed https://sourceware.org/bugzilla/show_bug.cgi?id=29012
> >>> (milestone 2.39, way larger than the current required version: 2.25)
> >>>
> >>> Switching to assembly output doesn't seem bad :-)
> >>>
> >>> If you keep the compiler driver option but need to refactor the nearby
> >>> code, you may drop -fno-unit-at-a-time. It was added in 2006 (somewhere
> >>> between GCC 4.1 and 4.4), while glibc requires GCC>=6.2.
> >>
> >> Good to know we won't need to rely on compiler flags to get the expected
> >> correct asm directives. I am still struggling to get a fix without resorting
> >> to compiler flags, but without much success.  Trying to move it to assembly
> >> might be tricky, I am not sure if the data directives would be architecture
> >> agnostic.
> >
> > Many directives are architecture-independent:
> > https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops
> > binutils-gdb/gas/read.c:346 The `portable[]` array.
>
> I think we can make it work with asciz directive.
>
> >
> > To support Clang, no refactoring is probably needed: just change
> > fno_unit_at_a_time to only specify -fno-toplevel-reorder (and rename
> > it), not th legacy -fno-unit-at-a-time.
>
> Afaik llvm does not support -fno-toplevel-reorder

It doesn't, but its integrated assembler does not need the option to
have the desired semantics. I have a note that the new GNU as behavior
is quite similar to LLVM's integrated assembler since 2014-03:
https://sourceware.org/bugzilla/show_bug.cgi?id=29012#c1
  
Adhemerval Zanella Netto April 5, 2022, 4:49 p.m. UTC | #11
On 05/04/2022 13:44, Fāng-ruì Sòng wrote:
> On Tue, Apr 5, 2022 at 10:40 AM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>>
>>
>> On 05/04/2022 13:22, Fāng-ruì Sòng wrote:
>>> On Tue, Apr 5, 2022 at 8:35 AM Adhemerval Zanella
>>> <adhemerval.zanella@linaro.org> wrote:
>>>>
>>>>
>>>>
>>>> On 04/04/2022 12:57, Fangrui Song wrote:
>>>>>
>>>>> On 2022-03-31, Adhemerval Zanella wrote:
>>>>>>
>>>>>>
>>>>>> On 31/03/2022 00:43, Fangrui Song wrote:
>>>>>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> On 30/03/2022 13:23, Fangrui Song wrote:
>>>>>>>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 30/03/2022 02:07, Fangrui Song wrote:
>>>>>>>>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>>>>>>>>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>>>>>>>>>>> is a rough replacement for this legacy option
>>>>>>>>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>>>>>>>>>>
>>>>>>>>>>> The reordering requirement does not seem to be needed any longer.
>>>>>>>>>>
>>>>>>>>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>>>>>>>>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
>>>>>>>>>> glibc ABI.
>>>>>>>>>>
>>>>>>>>>> I am trying to fix without resorting to compiler options.
>>>>>>>>>
>>>>>>>>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>        .globl  __GLIBC_2_1_sys_errlist
>>>>>>>>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
>>>>>>>>>         .type   __GLIBC_2_1_sys_errlist,@object
>>>>>>>>>         .size   __GLIBC_2_1_sys_errlist, 1000
>>>>>>>>>         .globl  __GLIBC_2_1__sys_errlist
>>>>>>>>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
>>>>>>>>>         .type   __GLIBC_2_1__sys_errlist,@object
>>>>>>>>>         .size   __GLIBC_2_1__sys_errlist, 1000
>>>>>>>>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
>>>>>>>>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
>>>>>>>>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
>>>>>>>>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
>>>>>>>>>         .globl  __GLIBC_2_3_sys_errlist
>>>>>>>>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
>>>>>>>>>         .type   __GLIBC_2_3_sys_errlist,@object
>>>>>>>>>         .size   __GLIBC_2_3_sys_errlist, 1008
>>>>>>>>>         .globl  __GLIBC_2_3__sys_errlist
>>>>>>>>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
>>>>>>>>>         .type   __GLIBC_2_3__sys_errlist,@object
>>>>>>>>>         .size   __GLIBC_2_3__sys_errlist, 1008
>>>>>>>>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
>>>>>>>>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
>>>>>>>>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
>>>>>>>>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
>>>>>>>>>         .globl  __GLIBC_2_4_sys_errlist
>>>>>>>>>
>>>>>>>>> I do not know whether GCC would reorder these macros. Even yes,
>>>>>>>>> that'd just change the .symtab entries in the relocatable object file.
>>>>>>>>> The linker behavior remains the same with reordering.
>>>>>>>>
>>>>>>>> It does not seem to, just remove the -fno-unit-at-a-time and issue make
>>>>>>>> check-abi and you will see that object size for the compat symbols
>>>>>>>> reference to _sys_err_internal instead of the define compat ones.
>>>>>>>
>>>>>>> I see. I think this is a brittle behavior in GNU assembler. Filed
>>>>>>> https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
>>>>>>> information. I have created a patch but I know that will not solve
>>>>>>> glibc's problem :(
>>>>>>
>>>>>> It would be good to have this fixes, but unfortunately we need a way
>>>>>> to handle this on older binutils.  I am kind worried that the only
>>>>>> possible way to actually fix this without resorting to any compiler
>>>>>> flags is coding the array definitions in assembly direct...
>>>>>
>>>>> The GNU assembler issue has been fixed https://sourceware.org/bugzilla/show_bug.cgi?id=29012
>>>>> (milestone 2.39, way larger than the current required version: 2.25)
>>>>>
>>>>> Switching to assembly output doesn't seem bad :-)
>>>>>
>>>>> If you keep the compiler driver option but need to refactor the nearby
>>>>> code, you may drop -fno-unit-at-a-time. It was added in 2006 (somewhere
>>>>> between GCC 4.1 and 4.4), while glibc requires GCC>=6.2.
>>>>
>>>> Good to know we won't need to rely on compiler flags to get the expected
>>>> correct asm directives. I am still struggling to get a fix without resorting
>>>> to compiler flags, but without much success.  Trying to move it to assembly
>>>> might be tricky, I am not sure if the data directives would be architecture
>>>> agnostic.
>>>
>>> Many directives are architecture-independent:
>>> https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops
>>> binutils-gdb/gas/read.c:346 The `portable[]` array.
>>
>> I think we can make it work with asciz directive.
>>
>>>
>>> To support Clang, no refactoring is probably needed: just change
>>> fno_unit_at_a_time to only specify -fno-toplevel-reorder (and rename
>>> it), not th legacy -fno-unit-at-a-time.
>>
>> Afaik llvm does not support -fno-toplevel-reorder
> 
> It doesn't, but its integrated assembler does not need the option to
> have the desired semantics. I have a note that the new GNU as behavior
> is quite similar to LLVM's integrated assembler since 2014-03:
> https://sourceware.org/bugzilla/show_bug.cgi?id=29012#c1

This is not what I am seeing on my clang branch, where clang with integrated
moves the global asm directives to the top of the file.  And it makes 
check-abi fail due the _sys_errlist/sys_errlist being with wrong value.
  
Florian Weimer April 5, 2022, 5:53 p.m. UTC | #12
* Adhemerval Zanella via Libc-alpha:

> This is not what I am seeing on my clang branch, where clang with integrated
> moves the global asm directives to the top of the file.  And it makes 
> check-abi fail due the _sys_errlist/sys_errlist being with wrong value.

You can move the directives to the bottom of the file by creating a
temporary .s file and #include that from a wrapper .S file that
#includes the .s file.

Or perhaps generate the assembler file directly, as in
elf/dl-debug-symbols.S, which solves the same problem.  Linux <errno.h>
should be includable directly from assembler, hopefully that's true for
the Hurd version as well.

Thanks,
Florian
  
Adhemerval Zanella Netto April 5, 2022, 8:01 p.m. UTC | #13
On 05/04/2022 14:53, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> This is not what I am seeing on my clang branch, where clang with integrated
>> moves the global asm directives to the top of the file.  And it makes 
>> check-abi fail due the _sys_errlist/sys_errlist being with wrong value.
> 
> You can move the directives to the bottom of the file by creating a
> temporary .s file and #include that from a wrapper .S file that
> #includes the .s file.

Not sure I am following your suggestion here, do you mean get the -S
output file from compiler?

> 
> Or perhaps generate the assembler file directly, as in
> elf/dl-debug-symbols.S, which solves the same problem.  Linux <errno.h>
> should be includable directly from assembler, hopefully that's true for
> the Hurd version as well.

Making an assembly file is really tricky here because _sys_errlist_internal
contains internal gap (the errno values are not strictly sequential). The
compiler handles by adding '.zero' commands, which is not easily.  I think
we might generate it though a script.
  
Florian Weimer April 5, 2022, 8:26 p.m. UTC | #14
* Adhemerval Zanella:

> On 05/04/2022 14:53, Florian Weimer wrote:
>> * Adhemerval Zanella via Libc-alpha:
>> 
>>> This is not what I am seeing on my clang branch, where clang with integrated
>>> moves the global asm directives to the top of the file.  And it makes 
>>> check-abi fail due the _sys_errlist/sys_errlist being with wrong value.
>> 
>> You can move the directives to the bottom of the file by creating a
>> temporary .s file and #include that from a wrapper .S file that
>> #includes the .s file.
>
> Not sure I am following your suggestion here, do you mean get the -S
> output file from compiler?

Yes, H.J. did that in earlier patches.  But I didn't like it back then. 8-p

> Making an assembly file is really tricky here because _sys_errlist_internal
> contains internal gap (the errno values are not strictly sequential). The
> compiler handles by adding '.zero' commands, which is not easily.  I think
> we might generate it though a script.

I think the input file is already generated by a script.

Thanks,
Florian
  
Adhemerval Zanella Netto April 5, 2022, 8:30 p.m. UTC | #15
On 05/04/2022 17:26, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> On 05/04/2022 14:53, Florian Weimer wrote:
>>> * Adhemerval Zanella via Libc-alpha:
>>>
>>>> This is not what I am seeing on my clang branch, where clang with integrated
>>>> moves the global asm directives to the top of the file.  And it makes 
>>>> check-abi fail due the _sys_errlist/sys_errlist being with wrong value.
>>>
>>> You can move the directives to the bottom of the file by creating a
>>> temporary .s file and #include that from a wrapper .S file that
>>> #includes the .s file.
>>
>> Not sure I am following your suggestion here, do you mean get the -S
>> output file from compiler?
> 
> Yes, H.J. did that in earlier patches.  But I didn't like it back then. 8-p

For dl-debug-symbols.S? I might take it as an example.

> 
>> Making an assembly file is really tricky here because _sys_errlist_internal
>> contains internal gap (the errno values are not strictly sequential). The
>> compiler handles by adding '.zero' commands, which is not easily.  I think
>> we might generate it though a script.
> 
> I think the input file is already generated by a script.

No, what is scripted is the tst-errno-manual (which checks the errlist.h
against manual/errno.texi).
  
Florian Weimer April 5, 2022, 8:40 p.m. UTC | #16
* Adhemerval Zanella:

> On 05/04/2022 17:26, Florian Weimer wrote:
>> * Adhemerval Zanella:
>> 
>>> On 05/04/2022 14:53, Florian Weimer wrote:
>>>> * Adhemerval Zanella via Libc-alpha:
>>>>
>>>>> This is not what I am seeing on my clang branch, where clang with integrated
>>>>> moves the global asm directives to the top of the file.  And it makes 
>>>>> check-abi fail due the _sys_errlist/sys_errlist being with wrong value.
>>>>
>>>> You can move the directives to the bottom of the file by creating a
>>>> temporary .s file and #include that from a wrapper .S file that
>>>> #includes the .s file.
>>>
>>> Not sure I am following your suggestion here, do you mean get the -S
>>> output file from compiler?
>> 
>> Yes, H.J. did that in earlier patches.  But I didn't like it back then. 8-p
>
> For dl-debug-symbols.S? I might take it as an example.

Yes, here's a link to one of the earlier patches:

  [PATCH] Extend struct r_debug to support multiple namespaces
  <https://sourceware.org/pipermail/libc-alpha/2021-August/130149.html>

In the end, I think it was easier to use a manually written assembler
file in that case, with the constants filled in via the .sym expander.

Thanks,
Florian
  
Adhemerval Zanella Netto April 5, 2022, 9:15 p.m. UTC | #17
On 05/04/2022 17:40, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> On 05/04/2022 17:26, Florian Weimer wrote:
>>> * Adhemerval Zanella:
>>>
>>>> On 05/04/2022 14:53, Florian Weimer wrote:
>>>>> * Adhemerval Zanella via Libc-alpha:
>>>>>
>>>>>> This is not what I am seeing on my clang branch, where clang with integrated
>>>>>> moves the global asm directives to the top of the file.  And it makes 
>>>>>> check-abi fail due the _sys_errlist/sys_errlist being with wrong value.
>>>>>
>>>>> You can move the directives to the bottom of the file by creating a
>>>>> temporary .s file and #include that from a wrapper .S file that
>>>>> #includes the .s file.
>>>>
>>>> Not sure I am following your suggestion here, do you mean get the -S
>>>> output file from compiler?
>>>
>>> Yes, H.J. did that in earlier patches.  But I didn't like it back then. 8-p
>>
>> For dl-debug-symbols.S? I might take it as an example.
> 
> Yes, here's a link to one of the earlier patches:
> 
>   [PATCH] Extend struct r_debug to support multiple namespaces
>   <https://sourceware.org/pipermail/libc-alpha/2021-August/130149.html>

Thanks, I found it on the my local inbox history.

> 
> In the end, I think it was easier to use a manually written assembler
> file in that case, with the constants filled in via the .sym expander.

I think for this case, it would be simpler to use H.J strategy, I really
don't want to re-implement what compiler might do to lay out a C array
to assembler.
  
Adhemerval Zanella Netto April 6, 2022, 3:35 p.m. UTC | #18
On 05/04/2022 18:15, Adhemerval Zanella wrote:
> 
> 
> On 05/04/2022 17:40, Florian Weimer wrote:
>> * Adhemerval Zanella:
>>
>>> On 05/04/2022 17:26, Florian Weimer wrote:
>>>> * Adhemerval Zanella:
>>>>
>>>>> On 05/04/2022 14:53, Florian Weimer wrote:
>>>>>> * Adhemerval Zanella via Libc-alpha:
>>>>>>
>>>>>>> This is not what I am seeing on my clang branch, where clang with integrated
>>>>>>> moves the global asm directives to the top of the file.  And it makes 
>>>>>>> check-abi fail due the _sys_errlist/sys_errlist being with wrong value.
>>>>>>
>>>>>> You can move the directives to the bottom of the file by creating a
>>>>>> temporary .s file and #include that from a wrapper .S file that
>>>>>> #includes the .s file.
>>>>>
>>>>> Not sure I am following your suggestion here, do you mean get the -S
>>>>> output file from compiler?
>>>>
>>>> Yes, H.J. did that in earlier patches.  But I didn't like it back then. 8-p
>>>
>>> For dl-debug-symbols.S? I might take it as an example.
>>
>> Yes, here's a link to one of the earlier patches:
>>
>>   [PATCH] Extend struct r_debug to support multiple namespaces
>>   <https://sourceware.org/pipermail/libc-alpha/2021-August/130149.html>
> 
> Thanks, I found it on the my local inbox history.
> 
>>
>> In the end, I think it was easier to use a manually written assembler
>> file in that case, with the constants filled in via the .sym expander.
> 
> I think for this case, it would be simpler to use H.J strategy, I really
> don't want to re-implement what compiler might do to lay out a C array
> to assembler.

And so it seems it does not really help clang, the integrated assembler
still reorganizes the global asm directives which breaks the required
ABI size directives.
  
Fangrui Song April 7, 2022, 7:02 a.m. UTC | #19
On 2022-04-05, Adhemerval Zanella wrote:
>
>
>On 05/04/2022 13:44, Fāng-ruì Sòng wrote:
>> On Tue, Apr 5, 2022 at 10:40 AM Adhemerval Zanella
>> <adhemerval.zanella@linaro.org> wrote:
>>>
>>>
>>>
>>> On 05/04/2022 13:22, Fāng-ruì Sòng wrote:
>>>> On Tue, Apr 5, 2022 at 8:35 AM Adhemerval Zanella
>>>> <adhemerval.zanella@linaro.org> wrote:
>>>>>
>>>>>
>>>>>
>>>>> On 04/04/2022 12:57, Fangrui Song wrote:
>>>>>>
>>>>>> On 2022-03-31, Adhemerval Zanella wrote:
>>>>>>>
>>>>>>>
>>>>>>> On 31/03/2022 00:43, Fangrui Song wrote:
>>>>>>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 30/03/2022 13:23, Fangrui Song wrote:
>>>>>>>>>> On 2022-03-30, Adhemerval Zanella wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 30/03/2022 02:07, Fangrui Song wrote:
>>>>>>>>>>>> 795985e4e751 in 2003 added -fno-unit-at-a-time to errlist.c and
>>>>>>>>>>>> siglist.c to "avoid reordering assembler output". -fno-toplevel-reorder
>>>>>>>>>>>> is a rough replacement for this legacy option
>>>>>>>>>>>> (https://sourceware.org/pipermail/gcc-patches/2006-January/186801.html).
>>>>>>>>>>>>
>>>>>>>>>>>> The reordering requirement does not seem to be needed any longer.
>>>>>>>>>>>
>>>>>>>>>>> We still need them for otherwise DEFINE_COMPAT_ERRLIST used on errlist-compat.c
>>>>>>>>>>> does not create _sys_errlist and _sys_siglist with expected sizes defined by
>>>>>>>>>>> glibc ABI.
>>>>>>>>>>>
>>>>>>>>>>> I am trying to fix without resorting to compiler options.
>>>>>>>>>>
>>>>>>>>>> DEFINE_COMPAT_ERRLIST does not expand to code/data, just reordeable directives:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>        .globl  __GLIBC_2_1_sys_errlist
>>>>>>>>>> .set __GLIBC_2_1_sys_errlist, _sys_errlist_internal
>>>>>>>>>>         .type   __GLIBC_2_1_sys_errlist,@object
>>>>>>>>>>         .size   __GLIBC_2_1_sys_errlist, 1000
>>>>>>>>>>         .globl  __GLIBC_2_1__sys_errlist
>>>>>>>>>> .set __GLIBC_2_1__sys_errlist, _sys_errlist_internal
>>>>>>>>>>         .type   __GLIBC_2_1__sys_errlist,@object
>>>>>>>>>>         .size   __GLIBC_2_1__sys_errlist, 1000
>>>>>>>>>> .symver __GLIBC_2_1_sys_nerr, sys_nerr@GLIBC_2.2.5
>>>>>>>>>> .symver __GLIBC_2_1__sys_nerr, _sys_nerr@GLIBC_2.2.5
>>>>>>>>>> .symver __GLIBC_2_1_sys_errlist, sys_errlist@GLIBC_2.2.5
>>>>>>>>>> .symver __GLIBC_2_1__sys_errlist, _sys_errlist@GLIBC_2.2.5
>>>>>>>>>>         .globl  __GLIBC_2_3_sys_errlist
>>>>>>>>>> .set __GLIBC_2_3_sys_errlist, _sys_errlist_internal
>>>>>>>>>>         .type   __GLIBC_2_3_sys_errlist,@object
>>>>>>>>>>         .size   __GLIBC_2_3_sys_errlist, 1008
>>>>>>>>>>         .globl  __GLIBC_2_3__sys_errlist
>>>>>>>>>> .set __GLIBC_2_3__sys_errlist, _sys_errlist_internal
>>>>>>>>>>         .type   __GLIBC_2_3__sys_errlist,@object
>>>>>>>>>>         .size   __GLIBC_2_3__sys_errlist, 1008
>>>>>>>>>> .symver __GLIBC_2_3_sys_nerr, sys_nerr@GLIBC_2.3
>>>>>>>>>> .symver __GLIBC_2_3__sys_nerr, _sys_nerr@GLIBC_2.3
>>>>>>>>>> .symver __GLIBC_2_3_sys_errlist, sys_errlist@GLIBC_2.3
>>>>>>>>>> .symver __GLIBC_2_3__sys_errlist, _sys_errlist@GLIBC_2.3
>>>>>>>>>>         .globl  __GLIBC_2_4_sys_errlist
>>>>>>>>>>
>>>>>>>>>> I do not know whether GCC would reorder these macros. Even yes,
>>>>>>>>>> that'd just change the .symtab entries in the relocatable object file.
>>>>>>>>>> The linker behavior remains the same with reordering.
>>>>>>>>>
>>>>>>>>> It does not seem to, just remove the -fno-unit-at-a-time and issue make
>>>>>>>>> check-abi and you will see that object size for the compat symbols
>>>>>>>>> reference to _sys_err_internal instead of the define compat ones.
>>>>>>>>
>>>>>>>> I see. I think this is a brittle behavior in GNU assembler. Filed
>>>>>>>> https://sourceware.org/bugzilla/show_bug.cgi?id=29012 with detailed
>>>>>>>> information. I have created a patch but I know that will not solve
>>>>>>>> glibc's problem :(
>>>>>>>
>>>>>>> It would be good to have this fixes, but unfortunately we need a way
>>>>>>> to handle this on older binutils.  I am kind worried that the only
>>>>>>> possible way to actually fix this without resorting to any compiler
>>>>>>> flags is coding the array definitions in assembly direct...
>>>>>>
>>>>>> The GNU assembler issue has been fixed https://sourceware.org/bugzilla/show_bug.cgi?id=29012
>>>>>> (milestone 2.39, way larger than the current required version: 2.25)
>>>>>>
>>>>>> Switching to assembly output doesn't seem bad :-)
>>>>>>
>>>>>> If you keep the compiler driver option but need to refactor the nearby
>>>>>> code, you may drop -fno-unit-at-a-time. It was added in 2006 (somewhere
>>>>>> between GCC 4.1 and 4.4), while glibc requires GCC>=6.2.
>>>>>
>>>>> Good to know we won't need to rely on compiler flags to get the expected
>>>>> correct asm directives. I am still struggling to get a fix without resorting
>>>>> to compiler flags, but without much success.  Trying to move it to assembly
>>>>> might be tricky, I am not sure if the data directives would be architecture
>>>>> agnostic.
>>>>
>>>> Many directives are architecture-independent:
>>>> https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops
>>>> binutils-gdb/gas/read.c:346 The `portable[]` array.
>>>
>>> I think we can make it work with asciz directive.
>>>
>>>>
>>>> To support Clang, no refactoring is probably needed: just change
>>>> fno_unit_at_a_time to only specify -fno-toplevel-reorder (and rename
>>>> it), not th legacy -fno-unit-at-a-time.
>>>
>>> Afaik llvm does not support -fno-toplevel-reorder
>>
>> It doesn't, but its integrated assembler does not need the option to
>> have the desired semantics. I have a note that the new GNU as behavior
>> is quite similar to LLVM's integrated assembler since 2014-03:
>> https://sourceware.org/bugzilla/show_bug.cgi?id=29012#c1
>
>This is not what I am seeing on my clang branch, where clang with integrated
>moves the global asm directives to the top of the file.  And it makes
>check-abi fail due the _sys_errlist/sys_errlist being with wrong value.

I see. For gas/testsuite/gas/elf/size.s, LLVM integrated assembler's
behavior matches GNU as. The glibc errlist.os example is more complex
due to a symbol assignment implied by .symver .

https://reviews.llvm.org/D123283 should fix it. It isn't a perfect fix but
works with most cases. I can request a backport to LLVM 14.0.1 if it lands.
  

Patch

diff --git a/config.make.in b/config.make.in
index 6d43e691f7..ecde84a7da 100644
--- a/config.make.in
+++ b/config.make.in
@@ -69,7 +69,6 @@  have-selinux = @have_selinux@
 have-libaudit = @have_libaudit@
 have-libcap = @have_libcap@
 have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
-fno-unit-at-a-time = @fno_unit_at_a_time@
 bind-now = @bindnow@
 have-hash-style = @libc_cv_hashstyle@
 use-default-link = @use_default_link@
diff --git a/configure b/configure
index 2a3cb49b0b..f836874a58 100755
--- a/configure
+++ b/configure
@@ -620,7 +620,6 @@  libc_cv_cc_loop_to_function
 libc_cv_cc_submachine
 libc_cv_cc_nofma
 libc_cv_mtls_dialect_gnu2
-fno_unit_at_a_time
 libc_cv_has_glob_dat
 libc_cv_hashstyle
 libc_cv_fpie
@@ -6319,37 +6318,6 @@  fi
 $as_echo "$libc_cv_has_glob_dat" >&6; }
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-toplevel-reorder -fno-section-anchors" >&5
-$as_echo_n "checking for -fno-toplevel-reorder -fno-section-anchors... " >&6; }
-if ${libc_cv_fno_toplevel_reorder+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat > conftest.c <<EOF
-int foo;
-EOF
-if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -S -fno-toplevel-reorder -fno-section-anchors
-			    conftest.c 1>&5'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }
-then
-  libc_cv_fno_toplevel_reorder=yes
-else
-  libc_cv_fno_toplevel_reorder=no
-fi
-rm -f conftest*
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_fno_toplevel_reorder" >&5
-$as_echo "$libc_cv_fno_toplevel_reorder" >&6; }
-if test $libc_cv_fno_toplevel_reorder = yes; then
-  fno_unit_at_a_time="-fno-toplevel-reorder -fno-section-anchors"
-else
-  fno_unit_at_a_time=-fno-unit-at-a-time
-fi
-
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -mtls-dialect=gnu2" >&5
 $as_echo_n "checking for -mtls-dialect=gnu2... " >&6; }
 if ${libc_cv_mtls_dialect_gnu2+:} false; then :
diff --git a/configure.ac b/configure.ac
index fa7d3c025b..ec1db36d46 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1478,25 +1478,6 @@  fi
 rm -f conftest*])
 AC_SUBST(libc_cv_has_glob_dat)
 
-AC_CACHE_CHECK(for -fno-toplevel-reorder -fno-section-anchors, libc_cv_fno_toplevel_reorder, [dnl
-cat > conftest.c <<EOF
-int foo;
-EOF
-if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -S -fno-toplevel-reorder -fno-section-anchors
-			    conftest.c 1>&AS_MESSAGE_LOG_FD])
-then
-  libc_cv_fno_toplevel_reorder=yes
-else
-  libc_cv_fno_toplevel_reorder=no
-fi
-rm -f conftest*])
-if test $libc_cv_fno_toplevel_reorder = yes; then
-  fno_unit_at_a_time="-fno-toplevel-reorder -fno-section-anchors"
-else
-  fno_unit_at_a_time=-fno-unit-at-a-time
-fi
-AC_SUBST(fno_unit_at_a_time)
-
 AC_CACHE_CHECK([for -mtls-dialect=gnu2], libc_cv_mtls_dialect_gnu2,
 [dnl
 cat > conftest.c <<EOF
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 435cd8904f..dbaecbd76e 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -333,8 +333,6 @@  CFLAGS-isoc99_vfscanf.c += -fexceptions
 CFLAGS-isoc99_vscanf.c += -fexceptions
 CFLAGS-isoc99_fscanf.c += -fexceptions
 CFLAGS-isoc99_scanf.c += -fexceptions
-CFLAGS-errlist.c += $(fno-unit-at-a-time)
-CFLAGS-siglist.c += $(fno-unit-at-a-time)
 
 # scanf14a.c and scanf16a.c test a deprecated extension which is no
 # longer visible under most conformance levels; see the source files