aranym bug, manifests as "ida_remove called for id=13" on recent kernels
Subsystems (4)
Al Viro
maintainer I've spent quite a while hunting that crap down; reverting VFS fix
mentioned in original thread *does* get rid of the symptoms, but so does the patch below.
What happens is this: if ->follow_link() (usually something like
stat("/proc/2/fd", ...) done by pidof(8)) return ERR_PTR(-....), we return
to __do_follow_link() and do the following:
*p = dentry->d_inode->i_op->follow_link(dentry, nd);
error = PTR_ERR(*p);
if (!IS_ERR(*p)) {
char *s = nd_get_link(nd);
error = 0;
if (s)
error = __vfs_follow_link(nd, s);
else if (nd->last_type == LAST_BIND) {
error = force_reval_path(&nd->path, nd);
if (error)
path_put(&nd->path);
}
}
return error;We _should_ return non-zero value; IS_ERR(ERR_PTR(-n)) is 1 and PTR_ERR(ERR_PTR(n)) is -n. What happens instead is that this thing actually returns 0. And no, it's not a miscompile. Patch below removes the symptoms of the bug, but only if both parts are present. I.e. *not* doing "report = 1" in proc_pid_follow_link() gives us visible breakage, despite the fact that report is initialized as 1 and nothing except proc_pid_follow_link() ever tries to assign anything to it. Seeing that fs/namei.c and fs/proc/base.c are compiled separately, we can exclude gcc problems.
The cheapest way to reproduce is to boot with init=/bin/sh, then mount /proc and have stat("/proc/2/exe", &st) called; if stat() returns 0, we are fscked. The critical part is between return from proc_exe_link() (we'll leave it via if (!mm) return -ENOENT;) to return from __do_follow_link() -> do_follow_link() -> link_path_walk().
If somebody familiar with aranym guts are up to debugging that, more power to them. If I would've seen it on real hardware, I'd suspect something weird going on with caches, but...
FWIW, it's observable on amd64 host; I haven't tried it on x86. Version of aranym is 0.9.6beta2-1 (one in lenny). Have fun...
Patch [*NOT* for inclusion into mainline, obviously] follows:
fs/namei.c +4 -0
@@ -524,6 +524,8 @@ static inline void path_to_nameidata(struct path *path, struct nameidata *nd) nd->path.dentry = path->dentry; } +int report =1 ; + static __always_inline int__do_follow_link (struct path *path,struct nameidata *nd,void **p) {
@@ -552,6 +554,8 @@ __do_follow_link(struct path *path, struct nameidata *nd, void **p)path_put (&nd->path); } } +if (report && !error &&IS_ERR (*p)) +printk ("fucked: %d %p\n" , error, *p);return error; }
fs/proc/base.c +1 -0
@@ -1513,6 +1513,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd) goto out; error =PROC_I (inode)->op.proc_get_link (inode, &nd->path); + {extern int report; report =1 ;} out:return ERR_PTR (error); }
Geert Uytterhoeven
maintainerQuoted 32 lines · Al Viro
I've spent quite a while hunting that crap down; reverting VFS fix mentioned in original thread *does* get rid of the symptoms, but so does the patch below.
What happens is this: if ->follow_link() (usually something like
stat("/proc/2/fd", ...)done by pidof(8)) returnERR_PTR(-....), we return to__do_follow_link()and do the following:
*p =dentry->d_inode->i_op->follow_link(dentry, nd); error =PTR_ERR(*p);
if (!IS_ERR(*p)) {
char *s =nd_get_link(nd);
error = 0;
if (s)
error =__vfs_follow_link(nd, s);
else if (nd->last_type==LAST_BIND) {
error =force_reval_path(&nd->path, nd); if (error)
path_put(&nd->path);
}
}
return error;We _should_ return non-zero value; IS_ERR(ERR_PTR(-n)) is 1 and PTR_ERR(ERR_PTR(n)) is -n. What happens instead is that this thing actually returns 0. And no, it's not a miscompile. Patch below removes the symptoms of the bug, but only if both parts are present. I.e. *not* doing "report = 1" in
proc_pid_follow_link()gives us visible breakage, despite the fact that report is initialized as 1 and nothing exceptproc_pid_follow_link()ever tries to assign anything to it. Seeing thatfs/namei.candfs/proc/base.care compiled separately, we can exclude gcc problems.
Quoted 5 lines
The cheapest way to reproduce is to boot with init=/bin/sh, then mount /proc and have
stat("/proc/2/exe", &st)called; ifstat()returns 0, we are fscked. The critical part is between return fromproc_exe_link()(we'll leave it via if (!mm) return-ENOENT;) to return from__do_follow_link()->do_follow_link()->link_path_walk().
I booted 2.6.36-rc7-atari-00360-g0dd2e6a (my current private test kernel) with init=/bin/sh, mounted /proc, and tried
for i in $(seq 1000); do stat /proc/2/exe; done
a few times, but I didn't see any ida_remove messages. It cannot read the /proc/2/exe symlink, though.
This is on aranym-0.9.9-1 from Ubuntu/amd64.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Al Viro
maintainerQuoted 9 lines · Geert Uytterhoeven
Quoted 5 lines
The cheapest way to reproduce is to boot with init=/bin/sh, then mount /proc and have
stat("/proc/2/exe", &st)called; ifstat()returns 0, we are fscked. ??The critical part is between return fromproc_exe_link()(we'll leave it via if (!mm) return-ENOENT;) to return from__do_follow_link()->do_follow_link()->link_path_walk().I booted 2.6.36-rc7-atari-00360-g0dd2e6a (my current private test kernel) with init=/bin/sh, mounted /proc, and tried
Quoted 6 lines
for i in $(seq 1000); do stat /proc/2/exe; donea few times, but I didn't see any
ida_removemessages. It cannot read the/proc/2/exesymlink, though.This is on aranym-0.9.9-1 from Ubuntu/amd64.
stat -L /proc/2/exec, otherwise you'll hit lstat() instead of stat(). And FWIW 0.9.10-1 squeeze/amd64 also triggers here...
Geert Uytterhoeven
maintainerQuoted 12 lines · Al Viro
Quoted 11 lines · Geert Uytterhoeven
Quoted 5 lines
The cheapest way to reproduce is to boot with init=/bin/sh, then mount /proc and have
stat("/proc/2/exe", &st)called; ifstat()returns 0, we are fscked. ??The critical part is between return fromproc_exe_link()(we'll leave it via if (!mm) return-ENOENT;) to return from__do_follow_link()->do_follow_link()->link_path_walk().I booted 2.6.36-rc7-atari-00360-g0dd2e6a (my current private test kernel) with init=/bin/sh, mounted /proc, and tried
for i in $(seq 1000); do stat
/proc/2/exe; done
Quoted 7 lines
Quoted 4 lines
a few times, but I didn't see any
ida_removemessages. It cannot read the/proc/2/exesymlink, though.This is on aranym-0.9.9-1 from Ubuntu/amd64.
stat -L
/proc/2/exec, otherwise you'll hitlstat()instead ofstat(). And FWIW 0.9.10-1 squeeze/amd64 also triggers here...
Still, just "stat: cannot stat `proc/2/exe': No such file or directory" here...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Al Viro
maintainerQuoted 6 lines · Geert Uytterhoeven
Quoted 4 lines
Quoted 1 line
This is on aranym-0.9.9-1 from Ubuntu/amd64.
stat -L
/proc/2/exec, otherwise you'll hitlstat()instead ofstat(). And FWIW 0.9.10-1 squeeze/amd64 also triggers here...Still, just "stat: cannot stat `proc/2/exe': No such file or directory" here...
Interesting... Which gcc version is used?
Al Viro
maintainerQuoted 9 lines · Al Viro
Quoted 6 lines · Geert Uytterhoeven
Quoted 4 lines
Quoted 1 line
This is on aranym-0.9.9-1 from Ubuntu/amd64.
stat -L
/proc/2/exec, otherwise you'll hitlstat()instead ofstat(). And FWIW 0.9.10-1 squeeze/amd64 also triggers here...Still, just "stat: cannot stat `proc/2/exe': No such file or directory" here...
Interesting... Which gcc version is used?
Argh... OK, going through aranym with debugger has exhonorated it. My apologies ;-/ It *is* gcc in sid. Testcase:
extern int foo(int);
void *bar(int n)
{
return (void *)foo(n);
}and gcc -S -O2 turns that into
bar:
link.w %fp,#0
unlk %fp
jra fooSpot the obvious bug... BTW, why on the Earth does debian-ports m68k tree use gcc-4.3 with Cthulhu-scaring 700Kb gzipped patch and does *not* have gcc-4.4?
Quoted 9 lines · Al Viro
Argh... OK, going through aranym with debugger has exhonorated it. My apologies ;-/ It *is* gcc in sid. Testcase:
extern int foo(int);
void *bar(int n){ return (void *)foo(n); }
Quoted 6 lines
and gcc -S -O2 turns that into
bar:link.w %fp,#0 unlk %fp jra foo
I presume the bug is that foo put the return value in %d0 while bar should have its return value in %a0. This function isn't eligible for the optimization being used due to this need to move the result into a different register.
Quoted 3 lines
Spot the obvious bug... BTW, why on the Earth does debian-ports m68k tree use gcc-4.3 with Cthulhu-scaring 700Kb gzipped patch and does *not* have gcc-4.4?
I believe that gcc-4.4 for m68k is being held up by the TLS support patches. While I haven't been personally involved to any great degree, I got the impression that the work is pretty much done other than getting it included.
Brad Boyer
[email protected]
Al Viro
maintainerQuoted 4 lines · Brad Boyer
I presume the bug is that foo put the return value in %d0 while bar should have its return value in %a0. This function isn't eligible for the optimization being used due to this need to move the result into a different register.
Yes.
Quoted 7 lines
Quoted 3 lines
Spot the obvious bug... BTW, why on the Earth does debian-ports m68k tree use gcc-4.3 with Cthulhu-scaring 700Kb gzipped patch and does *not* have gcc-4.4?
I believe that gcc-4.4 for m68k is being held up by the TLS support patches. While I haven't been personally involved to any great degree, I got the impression that the work is pretty much done other than getting it included.
What do autobuilders use, BTW?
Al Viro dixit:
Quoted 7 lines · Brad Boyer
Quoted 6 lines
Quoted 4 lines
Spot the obvious bug... BTW, why on the Earth does debian-ports m68k tree use gcc-4.3 with Cthulhu-scaring 700Kb gzipped patch and does *not* have gcc-4.4?
I believe that gcc-4.4 for m68k is being held up by the TLS support patches.
Yes, indeed. I’m working on gcc-4.4 but am stalled because, after finally getting a kernel to build, it has no support for nfeth. Finn Thain has kindly provided me with an eglibc+TLS sysroot tarball, which I can use to bootstrapp gcc-4.4+TLS then Debian’s eglibc+TLS, once I can boot into an aranym with a TLS capable kernel.
Quoted 1 line
What do autobuilders use, BTW?
They don’t function at the moment because 70% of the archive is either outdated or uninstallable on m68k. I’m mainly playing (as in game) buildd here because of that fact, since I didn’t want mksh to not show up on all architectures ;-) My goal is to get cowbuilder working then re-bootstrap enough of Debian/m68k to get the autobuilders working again.
Mikael Pettersson dixit:
Quoted 3 lines
It's gcc PR41302 which was fixed for gcc trunk on November 4 2009 in r153890. The patch backports easily to gcc-4.4 and solves the test case there (manual inspection using a cross). It also backports
[x] send unidiff
I’ll include that in my gcc build and then forward it to Debian once I got a working gcc, unless you want to push that to them already.
bye,
//mirabilos
Signature · 4 lines
I believe no one can invent an algorithm. One just happens to hit upon it when God enlightens him. Or only God invents algorithms, we merely copy them. If you don't believe in God, just consider God as Nature if you won't deny existence. -- Coywolf Qi Hunt
Quoted 7 lines · Thorsten Glaser
Mikael Pettersson dixit:
Quoted 3 lines
It's gcc PR41302 which was fixed for gcc trunk on November 4 2009 in r153890. The patch backports easily to gcc-4.4 and solves the test case there (manual inspection using a cross). It also backports
[x] send unidiff
http://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;a=commitdiff;h=d09fd72c630c4886367f1977cdb366aa82950e32
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Al Viro
maintainerQuoted 4 lines · Thorsten Glaser
Al Viro dixit:
Quoted 1 line · Brad Boyer
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Spot the obvious bug... BTW, why on the Earth does debian-ports m68k tree use gcc-4.3 with Cthulhu-scaring 700Kb gzipped patch and does *not* have gcc-4.4?
I believe that gcc-4.4 for m68k is being held up by the TLS support patches.
Yes, indeed. I???m working on gcc-4.4 but am stalled because, after finally getting a kernel to build, it has no support for nfeth.
Huh? Oh, you mean the net_device_ops transition missed inarch/m68k/emu/nfeth.c? Just add
static const struct net_device_ops nfeth_netdev_ops = {
.ndo_open = nfeth_open,
.ndo_stop = nfeth_stop,
.ndo_get_stats = nfeth_get_stats, .ndo_start_xmit = nfeth_xmit, .ndo_tx_timeout = nfeth_tx_timeout,
.ndo_validate_addr = eth_validate_addr,
};
in it and replace the assignments to ->open, etc. in nfeth_probe() with
dev->netdev_ops = &nfeth_netdev_ops;
and the sucker will work.
Below is what I'm using on top of mainline kernel; it's a combination of couple of patches in debian m68k kernel plus compile fixes. At least works well enough for booting with /dev/hda getting contents from file on host and network working well enough for ssh. With gcc-4.1 that seems to be enough. With 4.3... slapping assignment to global variable right before the return from proc_pid_follow_link() gets it to boot and work well enough for apt-get and compiles, but I wouldn't bet a dime on the correctness around failure exits all over the tree. This kind of miscompile is definitely triggered in a lot of places - anything that does return ERR_PTR(error) right after error = foo(...); is going to get fscked and it's not a rare thing. Amazing that it doesn't fall apart much harder...
BTW, now that I've tried allmodconfig build, 4.3 gives a bunch of ICE on e.g. ntfs. Cross-build, so it's not an underlying kernel breakage...
arch/m68k/Kconfig +31 -0
@@ -248,6 +248,37 @@ config SUN3 If you don't want to compile a kernel exclusively for a Sun 3, say N. +config NATFEAT + bool "ARAnyM emulator support" + depends on ATARI + help + This option enables support for ARAnyM native features, such as + access to a disk image as /dev/hda. Useful with the ARANYM option. + +config NFETH + tristate "NatFeat Ethernet support" + depends on NET_ETHERNET && NATFEAT + help + Say Y to include support for the ARAnyM NatFeat network device + which will emulate a regular ethernet device while presenting an + ethertap device to the host system. + +config NFBLOCK + tristate "NatFeat block device support" + depends on BLOCK && NATFEAT + help + Say Y to include support for the ARAnyM NatFeat block device + which allows direct access to the hard drives without using + the hardware emulation. + +config NFCON + tristate "NatFeat console driver" + depends on NATFEAT + help + Say Y to include support for the ARAnyM NatFeat console driver + which allows the console output to be redirected to the stderr + output of ARAnyM. + comment "Processor type" config M68020
arch/m68k/Makefile +1 -0
@@ -76,6 +76,7 @@ core-$(CONFIG_MVME16x) += arch/m68k/mvme16x/ core-$(CONFIG_BVME6000) += arch/m68k/bvme6000/ core-$(CONFIG_SUN3X) += arch/m68k/sun3x/ arch/m68k/sun3/ core-$(CONFIG_SUN3) += arch/m68k/sun3/ arch/m68k/sun3/prom/ +core-$(CONFIG_NATFEAT) += arch/m68k/emu/ core-$(CONFIG_M68040) += arch/m68k/fpsp040/ core-$(CONFIG_M68060) += arch/m68k/ifpsp060/ core-$(CONFIG_M68KFPU_EMU) += arch/m68k/math-emu/
arch/m68k/emu/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# +# Makefile for Linux arch/m68k/emu source directory +# + +obj-y += natfeat.o + +obj-$(CONFIG_NFETH) += nfeth.o +obj-$(CONFIG_NFBLOCK) += nfblock.o +obj-$(CONFIG_NFCON) += nfcon.o
arch/m68k/emu/natfeat.c new file +75 -0
75 lines not on this page · raw message
arch/m68k/emu/nfblock.c new file +195 -0
195 lines not on this page · raw message
arch/m68k/emu/nfcon.c new file +164 -0
164 lines not on this page · raw message
arch/m68k/emu/nfeth.c new file +287 -0
287 lines not on this page · raw message
arch/m68k/include/asm/natfeat.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* ARAnyM hardware support via Native Features (natfeats) +* +* Copyright (c) 2005 Petr Stehlik of ARAnyM dev team +* +* This software may be used and distributed according to the terms of +* the GNU General Public License (GPL), incorporated herein by reference. +*/ + +#ifndef _NATFEAT_H +#define _NATFEAT_H + +long nf_get_id (const char *feature_name); +long nf_call (long id, ...); + +void nf_init (void ); +void nf_shutdown (void ); + +void nfprint (const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 ))); + +# endif /* _NATFEAT_H */
arch/m68k/kernel/setup.c +5 -0
@@ -42,6 +42,7 @@#ifdef CONFIG_SUN3X #include <asm/dvma.h> #endif +#include <asm/natfeat.h> #if !FPSTATESIZE || !NR_IRQS #warning No CPU/platform type selected, your kernel will not work!
@@ -324,6 +325,10 @@ void __init setup_arch(char **cmdline_p)panic ("No configuration setup" ); } +#ifdef CONFIG_NATFEAT +nf_init (); +#endif +paging_init ();#ifndef CONFIG_SUN3
drivers/net/Kconfig +8 -0
@@ -418,6 +418,14 @@ config ATARILANCE on the AMD Lance chipset: RieblCard (with or without battery), or PAMCard VME (also the version by Rhotron, with different addresses). +config ATARI_ETHERNEC + tristate "Atari EtherNEC Ethernet support" + depends on NET_ETHERNET && ATARI && ATARI_ROM_ISA + help + Say Y to include support for the EtherNEC network adapter for the + ROM port. The driver works by polling instead of interrupts, so it + is quite slow. + config SUN3LANCE tristate "Sun3/Sun3x on-board LANCE support" depends on SUN3 || SUN3X
Al Viro dixit:
Quoted 1 line
Huh? Oh, you mean the
net_device_opstransition missed in
No, I mean that the Debian kernel apparently lost the m68k patches… I’ll leave that to those people.
Quoted 2 lines
BTW, now that I've tried allmodconfig build, 4.3 gives a bunch of ICE on e.g. ntfs. Cross-build, so it's not an underlying kernel breakage...
Probably GCC PR#37052 (first was btrfs for me). ‣ http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=598893
‣ http://wiki.debian.org/M68k/Gcc#iceinfindreloads
bye,
//mirabilos
Signature · 4 lines
I believe no one can invent an algorithm. One just happens to hit upon it when God enlightens him. Or only God invents algorithms, we merely copy them. If you don't believe in God, just consider God as Nature if you won't deny existence. -- Coywolf Qi Hunt
Quoted 2 lines · Al Viro
Below is what I'm using on top of mainline kernel; it's a combination of couple of patches in debian m68k kernel plus compile fixes.
Try Geert's linux-m68k tree.
Quoted 3 lines
This kind of miscompile is definitely triggered in a lot of places - anything that does return
ERR_PTR(error)right after error = foo(...); is going to get fscked and it's not a rare thing.
Only if they are optimized into tail calls.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Al Viro
maintainerQuoted 5 lines · Andreas Schwab
Quoted 2 lines · Al Viro
Below is what I'm using on top of mainline kernel; it's a combination of couple of patches in debian m68k kernel plus compile fixes.
Quoted 7 lines
Try Geert's linux-m68k tree.
Quoted 3 lines
This kind of miscompile is definitely triggered in a lot of places - anything that does return
ERR_PTR(error)right after error = foo(...); is going to get fscked and it's not a rare thing.Only if they are optimized into tail calls.
And with -O2 4.3 does exactly that.
BTW, any comments on signal patchset? Seems to work here, including the stack expansion fixes, but that's on aranym. I'll try to resurrect the real hardware, but that may take a while. If somebody could give it a beating in the meanwhile...
Al Viro
maintainerQuoted 4 lines · Al Viro
BTW, any comments on signal patchset? Seems to work here, including the stack expansion fixes, but that's on aranym. I'll try to resurrect the real hardware, but that may take a while. If somebody could give it a beating in the meanwhile...
Oh, lovely... One more signal bug (and a lot more on m68knommu): if we strace a process and signal is delivered during pagefault handling, you'll lose the second call of syscall_trace() on sigreturn(). If the signal is delivered during a syscall or during an interrupt, syscall_trace() is called twice on sigreturn() (as it does on all platforms). Fortunately, that's easy to fix - same as on alpha (calling syscall_trace in ret_from_signal if we are getting traced, just before doing RESTORE_SWITCH_STACK). Will test and post...
FWIW, on other targets we either have sys_{rt,}_sigreturn() done as normal functons (in which case the normal logics will take care of that), or have them return to place in (common) syscall exit path earlier than conditional call of syscall trace (mips, score), or check flags and do call ourselves (sparc, alpha since it had been fixed). AFAICS, m68k and m68knommu are the only ones buggered that way. On alpha we used to have it even worse - there we did only one call on sigreturn() unconditionally...
Geert Uytterhoeven
maintainerQuoted 4 lines · Al Viro
BTW, any comments on signal patchset? Seems to work here, including the stack expansion fixes, but that's on aranym. I'll try to resurrect the real hardware, but that may take a while. If somebody could give it a beating in the meanwhile...
I tried it on my Amiga 4000/040.
Without your patches, gdb gets stuck in state D+ when reaching a breakpoint:
| cassandra:~# gdb /tmp/hello | GNU gdb 6.4.90-debian | Copyright (C) 2006 Free Software Foundation, Inc. | GDB is free software, covered by the GNU General Public License, and you are | welcome to change it and/or distribute copies of it under certain conditions. | Type "show copying" to see the conditions. | There is absolutely no warranty for GDB. Type "show warranty" for details. | This GDB was configured as "m68k-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1". | | (gdb) break main | Breakpoint 1 at 0x800003fc: file /home/geert/hello.c, line 6. | (gdb) run | Starting program: /tmp/hello | | Breakpoint 1, main (argc=1, argv=0xefbeedb4) at /home/geert/hello.c:6
With your patches, it works a bit better:
| cassandra:~# gdb /tmp/hello
| GNU gdb 6.4.90-debian
| Copyright (C) 2006 Free Software Foundation, Inc.
| GDB is free software, covered by the GNU General Public License, and you are
| welcome to change it and/or distribute copies of it under certain conditions.
| Type "show copying" to see the conditions.
| There is absolutely no warranty for GDB. Type "show warranty" for details.
| This GDB was configured as "m68k-linux-gnu"...Using host
libthread_db library "/lib/libthread_db.so.1".
|
| (gdb) break main
| Breakpoint 1 at 0x800003fc: file /home/geert/hello.c, line 6.
| (gdb) run
| Starting program: /tmp/hello
|
| Breakpoint 1, main (argc=1, argv=0xefcc5db4) at /home/geert/hello.c:6
| 6 printf("Hello, world! [C]\n");
| (gdb) cont
| Continuing.
| Hello, world! [C]
|
| Program exited normally.
| (gdb) run
| Starting program: /tmp/hello
|
| Breakpoint 1, main (argc=1, argv=0xef85bdb4) at /home/geert/hello.c:6
| 6 printf("Hello, world! [C]\n");
| (gdb) next
| Hello, world! [C]After which gdb is stuck in S+, and /tmp/hello in t.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 11 lines · Thorsten Glaser
Mikael Pettersson dixit:
Quoted 3 lines
It's gcc PR41302 which was fixed for gcc trunk on November 4 2009 in r153890. The patch backports easily to gcc-4.4 and solves the test case there (manual inspection using a cross). It also backports
[x] send unidiff
I’ll include that in my gcc build and then forward it to Debian once I got a working gcc, unless you want to push that to them already.
This is what I have had in my repo since November last year, but it's only been minimally tested in a cross. Please push if/once it passes bootstrap + regtest.
gcc/
2009-11-10 Mikael Pettersson <[email protected]>
Backport from mainline:
2009-11-04 Maxim Kuvyrkov <[email protected]>
PR target/41302
* config/m68k/m68k.c (m68k_reg_present_p): New static function. (m68k_ok_for_sibcall_p): Handle different result return locations.
gcc/testsuite/
2009-11-10 Mikael Pettersson <[email protected]>
Backport from mainline: 2009-11-04 Carlos O'Donell <[email protected]> PR target/41302 * gcc.target/m68k/pr41302.c: New test.
gcc/config/m68k/m68k.c renamed from gcc/config/m68k/m68k.c.~1~ +47 -0
@@ -1374,6 +1374,30 @@ flags_in_68881 (void)return cc_status.flags &CC_IN_68881 ; } +/* Return true if PARALLEL contains register REGNO. */ +static bool +m68k_reg_present_p (const_rtx parallel,unsigned int regno) +{ +int i; + +if (REG_P (parallel) &®NO (parallel) == regno) +return true; + +if (GET_CODE (parallel) !=PARALLEL ) +return false; + +for (i =0 ; i <XVECLEN (parallel,0 ); ++i) + { +const_rtx x; + + x =XEXP (XVECEXP (parallel,0 , i),0 ); +if (REG_P (x) &®NO (x) == regno) +return true; + } + +return false; +} +/* Implement TARGET_FUNCTION_OK_FOR_SIBCALL_P. */ static bool
@@ -1386,6 +1410,26 @@ m68k_ok_for_sibcall_p (tree decl, tree eif (CALL_EXPR_STATIC_CHAIN (exp))return false; +if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl)))) + { +/* Check that the return value locations are the same. For +example that we aren't returning a value from the sibling in +a D0 register but then need to transfer it to a A0 register. */ +rtx cfun_value; +rtx call_value; + + cfun_value =FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (cfun->decl)), + cfun->decl); + call_value =FUNCTION_VALUE (TREE_TYPE (exp), decl); + +/* Check that the values are equal or that the result the callee +function returns is superset of what the current function returns. */ +if (!(rtx_equal_p (cfun_value, call_value) + || (REG_P (cfun_value) + &&m68k_reg_present_p (call_value,REGNO (cfun_value))))) +return false; + } + kind =m68k_get_function_kind (current_function_decl);if (kind == m68k_fk_normal_function)/* We can always sibcall from a normal function, because it's
@@ -4583,6 +4627,9 @@ m68k_libcall_value (enum machine_mode moreturn gen_rtx_REG (mode,D0_REG ); } +/* Location in which function value is returned. +NOTE: Due to differences in ABIs, don't call this function directly, +use FUNCTION_VALUE instead. */ rtx m68k_function_value (const_tree valtype, const_tree func ATTRIBUTE_UNUSED) {
gcc/testsuite/gcc.target/m68k/pr41302.c renamed from gcc/testsuite/gcc.target/m68k/pr41302.c.~1~ +14 -0
@@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-final { scan-assembler "move.l \%d0,\%a0" { target *linux* } } } */ + +struct pts { +int c; +}; + +unsigned int bar (struct pts *a,int b); + +struct pts *foo (struct pts *a,int b) +{ +return (struct pts *)bar (a, b); +}
Quoted 22 lines · Al Viro
Quoted 9 lines · Al Viro
Quoted 6 lines · Geert Uytterhoeven
Quoted 4 lines
Quoted 1 line
This is on aranym-0.9.9-1 from Ubuntu/amd64.
stat -L
/proc/2/exec, otherwise you'll hitlstat()instead ofstat(). And FWIW 0.9.10-1 squeeze/amd64 also triggers here...Still, just "stat: cannot stat `proc/2/exe': No such file or directory" here...
Interesting... Which gcc version is used?
Argh... OK, going through aranym with debugger has exhonorated it. My apologies ;-/ It *is* gcc in sid. Testcase:
extern int foo(int);
void *bar(int n){ return (void *)foo(n); }and gcc -S -O2 turns that into
bar:
Quoted 7 lines
link.w %fp,#0 unlk %fp jra fooSpot the obvious bug... BTW, why on the Earth does debian-ports m68k tree use gcc-4.3 with Cthulhu-scaring 700Kb gzipped patch and does *not* have gcc-4.4?
I can confirm that the bug exists in gcc-4.3.4 and gcc-4.4.5, but it has been fixed in gcc-4.5.1 which generates:
bar:
link.w %fp,#0
move.l 8(%fp),-(%sp)
jsr foo
move.l %d0,%a0
unlk %fp
rtsI don't yet know the gcc PR number or svn commit # for the fix (in case people want a backport).
Quoted 42 lines · Mikael Pettersson
Quoted 22 lines · Al Viro
Quoted 9 lines · Al Viro
Quoted 6 lines · Geert Uytterhoeven
Quoted 4 lines
Quoted 1 line
This is on aranym-0.9.9-1 from Ubuntu/amd64.
stat -L
/proc/2/exec, otherwise you'll hitlstat()instead ofstat(). And FWIW 0.9.10-1 squeeze/amd64 also triggers here...Still, just "stat: cannot stat `proc/2/exe': No such file or directory" here...
Interesting... Which gcc version is used?
Argh... OK, going through aranym with debugger has exhonorated it. My apologies ;-/ It *is* gcc in sid. Testcase:
extern int foo(int);
void *bar(int n){ return (void *)foo(n); }and gcc -S -O2 turns that into
bar:Quoted 7 lines
link.w %fp,#0 unlk %fp jra fooSpot the obvious bug... BTW, why on the Earth does debian-ports m68k tree use gcc-4.3 with Cthulhu-scaring 700Kb gzipped patch and does *not* have gcc-4.4?
I can confirm that the bug exists in gcc-4.3.4 and gcc-4.4.5, but it has been fixed in gcc-4.5.1 which generates:
bar:
link.w %fp,#0 move.l 8(%fp),-(%sp) jsr foo move.l %d0,%a0 unlk %fp rts
Quoted 2 lines
I don't yet know the gcc PR number or svn commit # for the fix (in case people want a backport).
It's gcc PR41302 which was fixed for gcc trunk on November 4 2009 in r153890. The patch backports easily to gcc-4.4 and solves the test case there (manual inspection using a cross). It also backports easily to gcc-4.3 but I haven't tested it there.
Quoted 11 lines · Mikael Pettersson
I can confirm that the bug exists in gcc-4.3.4 and gcc-4.4.5, but it has been fixed in gcc-4.5.1 which generates:
bar:
link.w %fp,#0 move.l 8(%fp),-(%sp) jsr foo move.l %d0,%a0 unlk %fp rts
Quoted 2 lines
I don't yet know the gcc PR number or svn commit # for the fix (in case people want a backport).
See http://gcc.gnu.org/PR41302
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Geert Uytterhoeven
maintainerQuoted 9 lines · Al Viro
Quoted 6 lines · Geert Uytterhoeven
Quoted 4 lines
Quoted 1 line
This is on aranym-0.9.9-1 from Ubuntu/amd64.
stat -L
/proc/2/exec, otherwise you'll hitlstat()instead ofstat(). And FWIW 0.9.10-1 squeeze/amd64 also triggers here...Still, just "stat: cannot stat `proc/2/exe': No such file or directory" here...
Interesting... Which gcc version is used?
Good old gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds