Skip to contentSkip to conversation

IPv4 NAT doesn't compile in 2.4.4

DISCUSSION Russell King 3 participants 5 messages Apr 28, 2001 – May 2, 2001

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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 ([email protected]) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html

#1 lore raw
Quoted 9 lines · Russell King

ip_nat_standalone.c:

static int init_or_cleanup(int init)
{
...
cleanup_nat:

        ip_nat_cleanup();

...
}

Call ip_nat_cleanup();

Quoted 7 lines

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.

Quoted 2 lines

*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
[email protected]

#2 lore raw
In reply to Russell King
Quoted 1 line · David S. Miller

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")))

Quoted 1 line

From x86 vmlinux.lds:

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

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.

Quoted 1 line

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

Try x86.

Quoted 4 lines

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.

Quoted 2 lines

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 ([email protected]) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html

#3 lore raw
Quoted 8 lines · Russell King
Quoted 1 line

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
[email protected]

#4 lore raw
In reply to Russell King

In message <[email protected]> you write:

Quoted 2 lines

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.

net/ipv4/netfilter/ip_nat_core.c +3 -2
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
@@ -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