[Bug ipa/105326] aarch64: functions affected by irrelevant function changes

2022-04-21 Thread nobuta.keiya at fujitsu dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105326

--- Comment #4 from Keiya Nobuta  ---
Thank you for the information.
Can it be suppressed by option?

[Bug c/105326] aarch64: functions affected by irrelevant function changes

2022-04-21 Thread nobuta.keiya at fujitsu dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105326

--- Comment #1 from Keiya Nobuta  ---
Created attachment 52842
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52842=edit
The .i file of patched source

[Bug c/105326] New: aarch64: functions affected by irrelevant function changes

2022-04-21 Thread nobuta.keiya at fujitsu dot com via Gcc-bugs
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=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.20413 +0900
+++ /dev/fd/62  2022-04-21 15:52:37.20413 +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:

  :
0:  d503233fpaciasp
-   4:  a9be7bfdstp x29, x30, [sp, #-32]!
-   8:  910003fdmov x29, sp
-   c:  a90153f3stp x19, x20, [sp, #16]
-  10:  aa0003f3mov x19, x0
-  14:  d2800034mov x20, #0x1   // #1
-  18:  f9400260ldr x0, [x19]
-  1c:  37000140tbnzw0, #0, 44 
-  20:  9400bl  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