public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* IPv4 NAT doesn't compile in 2.4.4
@ 2001-04-28 16:25 Russell King
  2001-04-28 21:07 ` David S. Miller
  2001-05-02  4:57 ` Rusty Russell
  0 siblings, 2 replies; 5+ messages in thread
From: Russell King @ 2001-04-28 16:25 UTC (permalink / raw)
  To: linux-kernel

net/network.o: In function `init_or_cleanup':
net/network.o(.text+0x4a530): relocation truncated to fit: R_ARM_PC24 ip_nat_cleanup

says it all.

ip_nat_standalone.c:

static int init_or_cleanup(int init)
{
...
 cleanup_nat:
        ip_nat_cleanup();
...
}

ip_nat_core:

void __exit ip_nat_cleanup(void)
{
        ip_ct_selective_cleanup(&clean_nat, NULL);
        ip_conntrack_destroyed = NULL;
}

*Don't* do this - its fundamentally wrong.  Code in the kernel should _not_
reference code that has been removed by the linker.

--
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: IPv4 NAT doesn't compile in 2.4.4
  2001-04-28 16:25 IPv4 NAT doesn't compile in 2.4.4 Russell King
@ 2001-04-28 21:07 ` David S. Miller
  2001-04-28 21:21   ` Russell King
  2001-05-02  4:57 ` Rusty Russell
  1 sibling, 1 reply; 5+ messages in thread
From: David S. Miller @ 2001-04-28 21:07 UTC (permalink / raw)
  To: Russell King; +Cc: linux-kernel


Russell King writes:
 > ip_nat_standalone.c:
 > 
 > static int init_or_cleanup(int init)
 > {
 > ...
 >  cleanup_nat:
 >         ip_nat_cleanup();
 > ...
 > }

Call ip_nat_cleanup();

 > ip_nat_core:
 > 
 > void __exit ip_nat_cleanup(void)
 > {
 >         ip_ct_selective_cleanup(&clean_nat, NULL);
 >         ip_conntrack_destroyed = NULL;
 > }

Define ip_nat_cleanup() as an __exit function.

 > *Don't* do this - its fundamentally wrong.  Code in the kernel should _not_
 > reference code that has been removed by the linker.

Why would ip_nat_cleanup() be removed by the linker?  All the "unused"
attribute should do is shut up gcc if the thing is marked static yet
not called.  The GCC manual even states "... means that the function
is meant to be possibly unused.  GNU CC will not produce a warning
for this function."  It makes no mention of any effect on the actual
code output, or that the linker will delete it.

It doesn't remove the function on any platform I could test this on.

If the linker removed it, why did it give a relocation truncation
error instead of a missing symbol error?  And more importantly, what
specifically was the reason that the linker removed the function on
ARM, what made this happen?

Please explain this in detail so we don't have to guess as I have
seen no other report of this.

Later,
David S. Miller
davem@redhat.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: IPv4 NAT doesn't compile in 2.4.4
  2001-04-28 21:07 ` David S. Miller
@ 2001-04-28 21:21   ` Russell King
  2001-04-28 21:24     ` David S. Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Russell King @ 2001-04-28 21:21 UTC (permalink / raw)
  To: David S. Miller; +Cc: linux-kernel

On Sat, Apr 28, 2001 at 02:07:53PM -0700, David S. Miller wrote:
> Why would ip_nat_cleanup() be removed by the linker?

Because we explicitly tell the linker to drop all code marked as
__exit:

#define __exit          __attribute__ ((unused, __section__(".text.exit")))


>From x86 vmlinux.lds:

  /* Sections to be discarded */
  /DISCARD/ : {
        *(.text.exit)
        *(.data.exit)
        *(.exitcall.exit)
        }

>  All the "unused"
> attribute should do is shut up gcc if the thing is marked static yet
> not called.  The GCC manual even states "... means that the function
> is meant to be possibly unused.  GNU CC will not produce a warning
> for this function."  It makes no mention of any effect on the actual
> code output, or that the linker will delete it.

I quote from the ld info pages:

   The special output section name `/DISCARD/' may be used to discard
input sections.  Any input sections which are assigned to an output
section named `/DISCARD/' are not included in the output file.

> It doesn't remove the function on any platform I could test this on.

Try x86.

> If the linker removed it, why did it give a relocation truncation
> error instead of a missing symbol error?  And more importantly, what
> specifically was the reason that the linker removed the function on
> ARM, what made this happen?

Architecture independent linker behaviour.

> Please explain this in detail so we don't have to guess as I have
> seen no other report of this.

The reason it shows up on ARM is because the relocation is not 32-bit
long, and therefore the relocation it is trying to encode generates
an error.

(I'm presuming that it was allocating the symbol an address of zero,
but I haven't checked this since trying to call a non-present section
seems a bit stupid to start with).

--
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: IPv4 NAT doesn't compile in 2.4.4
  2001-04-28 21:21   ` Russell King
@ 2001-04-28 21:24     ` David S. Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David S. Miller @ 2001-04-28 21:24 UTC (permalink / raw)
  To: Russell King; +Cc: linux-kernel


Russell King writes:
 > >From x86 vmlinux.lds:
 > 
 >   /* Sections to be discarded */
 >   /DISCARD/ : {
 >         *(.text.exit)
 >         *(.data.exit)
 >         *(.exitcall.exit)
 >         }

Thanks, this is the part I didn't catch.  If you had said this in
the first email, I would have understood fully from the beginning.

Later,
David S. Miller
davem@redhat.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: IPv4 NAT doesn't compile in 2.4.4
  2001-04-28 16:25 IPv4 NAT doesn't compile in 2.4.4 Russell King
  2001-04-28 21:07 ` David S. Miller
@ 2001-05-02  4:57 ` Rusty Russell
  1 sibling, 0 replies; 5+ messages in thread
From: Rusty Russell @ 2001-05-02  4:57 UTC (permalink / raw)
  To: Russell King; +Cc: torvalds, linux-kernel

In message <20010428172554.H21792@flint.arm.linux.org.uk> you write:
> net/network.o: In function `init_or_cleanup':
> net/network.o(.text+0x4a530): relocation truncated to fit: R_ARM_PC24 ip_nat_
cleanup

My bad: Russell, you're absolutely right.

Obvious fix below.

Thanks!
Rusty.

diff -urN -I \$.*\$ -X /tmp/kerndiff.guovnD --minimal linux-2.4.4-official/net/ipv4/netfilter/ip_nat_core.c tmp/net/ipv4/netfilter/ip_nat_core.c
--- linux-2.4.4-official/net/ipv4/netfilter/ip_nat_core.c	Tue May  1 12:27:32 2001
+++ tmp/net/ipv4/netfilter/ip_nat_core.c	Wed May  2 14:55:01 2001
@@ -890,13 +890,14 @@
 }
 
 /* Clear NAT section of all conntracks, in case we're loaded again. */
-static int __exit clean_nat(const struct ip_conntrack *i, void *data)
+static int clean_nat(const struct ip_conntrack *i, void *data)
 {
 	memset((void *)&i->nat, 0, sizeof(i->nat));
 	return 0;
 }
 
-void __exit ip_nat_cleanup(void)
+/* Not __exit: called from ip_nat_standalone.c:init_or_cleanup() --RR */
+void ip_nat_cleanup(void)
 {
 	ip_ct_selective_cleanup(&clean_nat, NULL);
 	ip_conntrack_destroyed = NULL;
--
Premature optmztion is rt of all evl. --DK

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-05-02  6:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-04-28 16:25 IPv4 NAT doesn't compile in 2.4.4 Russell King
2001-04-28 21:07 ` David S. Miller
2001-04-28 21:21   ` Russell King
2001-04-28 21:24     ` David S. Miller
2001-05-02  4:57 ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox