https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92030
Bug ID: 92030
Summary: Wrong asm code for aliases on MIPS.
Product: gcc
Version: 8.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: anikulin at dlink dot ru
Target Milestone: ---
Created attachment 47006
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47006&action=edit
preprocessed file for the tested source
GCC 8.2.0 and 5.5.0 were tried.
The bug was raised while building and running FRR software.
It appears on MIPS(el), whereas x86_64 and aarch are ok.
FRR uses a [may be] tricky way to define aliases in C code:
https://github.com/FRRouting/frr/blob/master/lib/memory.h#L148
The extracted, adapted and tested snippet looks like:
struct memtype {
const char *name;
struct memtype *next;
};
static struct memtype abc1 __attribute__((section(".data.mtypes"))) = {
.name = "OSPF",
.next = NULL,
};
extern struct memtype abc2[1];
__asm__(".equiv abc2, abc1\n"); //abc2 is an alias symbol for abc1
printf("@abc1 = %p, abc2 = %p, @abc2 = %p\n", &abc1, abc2, &abc2);
Getting values generates the following asm:
# for the format string ($4 ~ a0): GOT + LO:
lw $2,%got($LC1)($28)
addiu $4,$2,%lo($LC1)
# for abs1 (a1), GOT + LO:
lw $2,%got(abc1)($28)
addiu $5,$2,%lo(abc1)
# for abs2 and &abs2 (a2 and a3): GOT only(!) w/o LO:
lw $7,%got(abc2)($28)
lw $6,%got(abc2)($28)
so the live result is:
> @abc1 = 0x411010, abc2 = 0x410000, @abc2 = 0x410000
The alias'es address is not adjusted, it causes SIGSEGV.
Meanwhile the data were linked correctly:
00411010 d abc1
00411010 d abc2
The same snippet works fine on x86_64 printing equal values for all.
Also I tried gcc-5.5.0 for aarh64 and saw GOT+LO for all variables including
the alias symbol.
Looks like this is the MIPS-related issue.
ospf.i is attached
invoking: mipsel-dlink-linux-uclibc-cc -Os -fPIC -g -save-temps -c -o ospf.o
ospf.c
gcc:
Using built-in specs.
COLLECT_GCC=/opt/toolchains/mipsel-gcc8/bin/mipsel-dlink-linux-uclibc-cc.br_real
COLLECT_LTO_WRAPPER=/opt/toolchains/mipsel-gcc8/bin/../libexec/gcc/mipsel-dlink-linux-uclibc/8.2.0/lto-wrapper
Target: mipsel-dlink-linux-uclibc
Configured with: ./configure --prefix=/home/sanya/repos/buildroot/output/host
--sysconfdir=/home/sanya/repos/buildroot/output/host/etc --enable-static
--target=mipsel-dlink-linux-uclibc
--with-sysroot=/home/sanya/repos/buildroot/output/host/mipsel-dlink-linux-uclibc/sysroot
--enable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib
--disable-decimal-float --with-gmp=/home/sanya/repos/buildroot/output/host
--with-mpc=/home/sanya/repos/buildroot/output/host
--with-mpfr=/home/sanya/repos/buildroot/output/host
--with-pkgversion='Buildroot 2019.02-git-00493-g3dd8dd8a31'
--with-bugurl=http://bugs.buildroot.net/ --disable-libquadmath --enable-tls
--enable-plugins --enable-lto --disable-libmudflap --enable-threads
--with-isl=/home/sanya/repos/buildroot/output/host --with-float=soft
--with-arch=mips32r2 --with-abi=32 --with-nan=legacy --enable-languages=c,c++
--with-build-time-tools=/home/sanya/repos/buildroot/output/host/mipsel-dlink-linux-uclibc/bin
--enable-shared --enable-libgomp
Thread model: posix
gcc version 8.2.0 (Buildroot 2019.02-git-00493-g3dd8dd8a31)
COMPILER_PATH=/opt/toolchains/mipsel-gcc8/bin/../libexec/gcc/mipsel-dlink-linux-uclibc/8.2.0/:/opt/toolchains/mipsel-gcc8/bin/../libexec/gcc/:/opt/toolchains/mipsel-gcc8/bin/../lib/gcc/mipsel-dlink-linux-uclibc/8.2.0/../../../../mipsel-dlink-linux-uclibc/bin/
LIBRARY_PATH=/opt/toolchains/mipsel-gcc8/bin/../lib/gcc/mipsel-dlink-linux-uclibc/8.2.0/:/opt/toolchains/mipsel-gcc8/bin/../lib/gcc/:/opt/toolchains/mipsel-gcc8/bin/../lib/gcc/mipsel-dlink-linux-uclibc/8.2.0/../../../../mipsel-dlink-linux-uclibc/lib/:/opt/toolchains/mipsel-gcc8/mipsel-dlink-linux-uclibc/sysroot/lib/:/opt/toolchains/mipsel-gcc8/mipsel-dlink-linux-uclibc/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-fstack-protector' '-v' '-march=mips32r2' '-mabi=32'
'-msoft-float' '-mnan=legacy' '-mllsc' '-mips32r2' '-mno-shared' '-EL'