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

            Bug ID: 105326
           Summary: aarch64: functions affected by irrelevant function
                    changes
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nobuta.keiya at fujitsu dot com
  Target Milestone: ---

Created attachment 52841
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52841&action=edit
The .i file of original source

When making the Linux kernel with minor change patch, gcc of aarch64 is
unexpectedly changing functions that is not call-related the function affected
by patch.


$ cd github/torvalds/linux
$ git describe
v5.17

To compare functions, add the following options:
$ export KCFLAGS="-ffunction-sections"

Make original object, and rename it to remember original object.
$ make mm/slub.o
$ mv mm/slub.o orig.o

Apply patch the following:
$ cat a.patch
diff -Nupr src.orig/mm/slub.c src/mm/slub.c
--- src.orig/mm/slub.c  2021-11-17 22:21:43.993307847 -0500
+++ src/mm/slub.c       2021-11-17 22:22:01.122335563 -0500
@@ -5910,6 +5910,9 @@ void get_slabinfo(struct kmem_cache *s,
        int node;
        struct kmem_cache_node *n;

+       if (!jiffies)
+               printk("slabinfo\n");
+
        for_each_kmem_cache_node(s, node, n) {
                nr_slabs += node_nr_slabs(n);
                nr_objs += node_nr_objs(n);
$ git apply a.patch

Make patched object, and rename it.
$ make mm/slub.o
$ mv mm/slub.o patched.o

Comparing the results of both objdumps, I can see the difference in the
following functions:
- bit_spin_lock.constprop.0
- add_location.constprop.0.isra.0
- __check_heap_object
- get_slabinfo

For example, diff of bit_spin_lock.constprop.0 is shown:

$ diff -u <(objdump -Dr -j .text.bit_spin_lock_constprop.0 orig.o)
          <(objdump -Dr -j .text.bit_spin_lock_constprop.0 patched.o)
--- /dev/fd/63  2022-04-21 15:52:37.204130000 +0900
+++ /dev/fd/62  2022-04-21 15:52:37.204130000 +0900
@@ -1,37 +1,29 @@

-orig/slub.o:     file format elf64-littleaarch64
+patched/slub.o:     file format elf64-littleaarch64


 Disassembly of section .text.bit_spin_lock.constprop.0:

 0000000000000000 <bit_spin_lock.constprop.0>:
    0:  d503233f        paciasp
-   4:  a9be7bfd        stp     x29, x30, [sp, #-32]!
-   8:  910003fd        mov     x29, sp
-   c:  a90153f3        stp     x19, x20, [sp, #16]
-  10:  aa0003f3        mov     x19, x0
-  14:  d2800034        mov     x20, #0x1                       // #1
-  18:  f9400260        ldr     x0, [x19]
-  1c:  37000140        tbnz    w0, #0, 44 <bit_spin_lock.constprop.0+0x44>
-  20:  94000000        bl      0 <bit_spin_lock.constprop.0>
-                       20: R_AARCH64_CALL26    .text.system_uses_lse_atomics
<..snip..>


I looked at functions other than get_slabinfo(), but it doesn't look like it's
called by get_slabinfo(), or calls get_slabinfo(). Comparing the objects seems
to differ in how the registers are used and whether inline functions are
expanded.

Also, changing the kernel version and doing the same seems to change
percpu_ref_put_many.constprop.0 and memcg_slab_free_hook.

I would like to know why this happens.


Using gcc from Fedora:
$ gcc v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/11/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin
--enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-11.2.1-20220127/obj-aarch64-redhat-linux/isl-install
--enable-gnu-indirect-function --build=aarch64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC)


Full gcc cmdline:
gcc -Wp,-MMD,mm/.slub.o.d -nostdinc -I./arch/arm64/include
-I./arch/arm64/include/generated  -I./include -I./arch/arm64/include/uapi
-I./arch/arm64/include/generated/uapi -I./include/uapi
-I./include/generated/uapi -include ./include/linux/compiler-version.h -include
./include/linux/kconfig.h -include ./include/linux/compiler_types.h
-D__KERNEL__ -mlittle-endian -DCC_USING_PATCHABLE_FUNCTION_ENTRY
-DKASAN_SHADOW_SCALE_SHIFT= -fmacro-prefix-map=./= -Wall -Wundef
-Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common
-fshort-wchar -fno-PIE -Werror=implicit-function-declaration
-Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89
-mgeneral-regs-only -DCONFIG_CC_HAS_K_CONSTRAINT=1 -Wno-psabi -mabi=lp64
-fno-asynchronous-unwind-tables -fno-unwind-tables
-mbranch-protection=pac-ret+leaf+bti -Wa,-march=armv8.5-a
-DARM64_ASM_ARCH='"armv8.5-a"' -DKASAN_SHADOW_SCALE_SHIFT=
-fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation
-Wno-format-overflow -Wno-address-of-packed-member -O2
-fno-allow-store-data-races -Wframe-larger-than=1024 -fno-stack-protector
-Wimplicit-fallthrough=5 -Wno-main -Wno-unused-but-set-variable
-Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls
-fno-stack-clash-protection -fpatchable-function-entry=2
-fno-inline-functions-called-once -Wdeclaration-after-statement -Wvla
-Wno-pointer-sign -Wcast-function-type -Wno-stringop-truncation
-Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict
-Wno-maybe-uninitialized -Wno-alloc-size-larger-than -fno-strict-overflow
-fno-stack-check -fconserve-stack -Werror=date-time
-Werror=incompatible-pointer-types -Werror=designated-init
-Wno-packed-not-aligned -g -gdwarf-4 -ffunction-sections -ffunction-sections
-fdata-sections    -DKBUILD_MODFILE='"mm/slub"' -DKBUILD_BASENAME='"slub"'
-DKBUILD_MODNAME='"slub"' -D__KBUILD_MODNAME=kmod_slub -c -o mm/slub.o
mm/slub.c


I tried the same thing using a cross-compiler builded by yocto, I see same
issue with "aarch64-poky-linux-gcc (GCC) 11.1.0" but I didn't see this issue
with "aarch64-poky-linux-gcc (GCC) 10.3.0". This seems to happen with aarch64
gcc-11.1.0 and later.

Reply via email to