Go to file
Stafford Horne 1bac7d31a1 or1k: Fix clobbering of _mcount argument if fPIC is enabled
Recently we changed the PROFILE_HOOK _mcount call to pass in the link
register as an argument.  This actually does not work when the _mcount
call uses a PLT because the GOT register setup code ends up getting
inserted before the PROFILE_HOOK and clobbers the link register
argument.

These glibc tests are failing:
  gmon/tst-gmon-pie-gprof
  gmon/tst-gmon-static-gprof

This patch fixes this by saving the instruction that stores the Link
Register to the _mcount argument and then inserts the GOT register setup
instructions after that.

For example:

main.c:

    extern int e;

    int f2(int a) {
      return a + e;
    }

    int f1(int a) {
      return f2 (a + a);
    }

    int main(int argc, char ** argv) {
      return f1 (argc);
    }

Compiled:

    or1k-smh-linux-gnu-gcc -Wall -c -O2 -fPIC -pg -S main.c

Before Fix:

    main:
        l.addi  r1, r1, -16
        l.sw    8(r1), r2
        l.sw    0(r1), r16
        l.addi  r2, r1, 16   # Keeping FP, but not needed
        l.sw    4(r1), r18
        l.sw    12(r1), r9
        l.jal   8            # GOT Setup clobbers r9 (Link Register)
         l.movhi        r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
        l.ori   r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
        l.add   r16, r16, r9
        l.or    r18, r3, r3
        l.or    r3, r9, r9    # This is not the original LR
        l.jal   plt(_mcount)
         l.nop

        l.jal   plt(f1)
         l.or    r3, r18, r18
        l.lwz   r9, 12(r1)
        l.lwz   r16, 0(r1)
        l.lwz   r18, 4(r1)
        l.lwz   r2, 8(r1)
        l.jr    r9
         l.addi  r1, r1, 16

After the fix:

    main:
        l.addi  r1, r1, -12
        l.sw    0(r1), r16
        l.sw    4(r1), r18
        l.sw    8(r1), r9
        l.or    r18, r3, r3
        l.or    r3, r9, r9    # We now have r9 (LR) set early
        l.jal   8             # Clobbers r9 (Link Register)
         l.movhi        r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
        l.ori   r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
        l.add   r16, r16, r9
        l.jal   plt(_mcount)
         l.nop

        l.jal   plt(f1)
         l.or    r3, r18, r18
        l.lwz   r9, 8(r1)
        l.lwz   r16, 0(r1)
        l.lwz   r18, 4(r1)
        l.jr    r9
         l.addi  r1, r1, 12

Fixes: 308531d148 ("or1k: Add return address argument to _mcount call")

gcc/ChangeLog:
	* config/or1k/or1k-protos.h (or1k_profile_hook): New function.
	* config/or1k/or1k.h (PROFILE_HOOK): Change macro to reference
	new function or1k_profile_hook.
	* config/or1k/or1k.c (struct machine_function): Add new field
	set_mcount_arg_insn.
	(or1k_profile_hook): New function.
	(or1k_init_pic_reg): Update to inject pic rtx after _mcount arg
	when profiling.
	(or1k_frame_pointer_required): Frame pointer no longer needed
	when profiling.
2021-11-13 07:58:00 +09:00
c++tools
config
contrib Daily bump. 2021-11-09 00:16:21 +00:00
fixincludes
gcc or1k: Fix clobbering of _mcount argument if fPIC is enabled 2021-11-13 07:58:00 +09:00
gnattools
gotools
include openmp: Relax handling of implicit map vs. existing device mappings 2021-11-12 20:29:48 +08:00
INSTALL
intl
libada
libatomic
libbacktrace libbacktrace: fix UBSAN issues 2021-11-12 15:06:12 +01:00
libcc1
libcody Daily bump. 2021-11-02 00:16:32 +00:00
libcpp Daily bump. 2021-11-02 00:16:32 +00:00
libdecnumber
libffi Daily bump. 2021-11-05 00:16:36 +00:00
libgcc Daily bump. 2021-11-12 00:16:32 +00:00
libgfortran
libgo
libgomp libgomp: Unbreak gcn offload build 2021-11-12 16:11:02 +01:00
libiberty
libitm
libobjc
liboffloadmic
libphobos
libquadmath
libsanitizer libsanitizer: update LOCAL_PATCHES. 2021-11-05 18:21:42 +01:00
libssp
libstdc++-v3 libstdc++: Print assertion messages to stderr [PR59675] 2021-11-12 12:23:10 +00:00
libvtv
lto-plugin
maintainer-scripts
zlib
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2021-11-04 00:16:32 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Clarify the policy WRT the Write After Approval list 2021-11-03 17:05:48 +00:00
Makefile.def Make opcodes configure depend on bfd configure 2021-11-12 18:34:12 +10:30
Makefile.in Make opcodes configure depend on bfd configure 2021-11-12 18:34:12 +10:30
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.