Skip to contentSkip to conversation

uml: remove support for CONFIG_STATIC_LINK

PATCH In review Brendan Higgins 5 participants 10 messages Dec 9, 2019 – Dec 12, 2019 1 message not in the archive User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uml: remove support for CONFIG_STATIC_LINK

CONFIG_STATIC_LINK appears to have been broken since before v4.20. It doesn't play nice with CONFIG_UML_NET_VECTOR=y:

/usr/bin/ld: arch/um/drivers/vector_user.o: in function `user_init_socket_fds': vector_user.c:(.text+0x430): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

And it seems to break the ptrace check:

Checking that ptrace can change system call numbers...check_ptrace :
child exited with exitcode 6, while expecting 0; status 0x67f
[1] 126822 abort ./linux mem=256M

(Apparently, a patch was recently discussed that fixes this - around v5.5-rc1[1] - but the fact that this was broken for over a year remains.)

According to Anton, PCAP throws even more warnings, and the resulting binary isn't really even static anyway, so there is really no point in keeping this config around[2].

Link[1]: https://www.spinics.net/lists/stable/msg346933.html
Link[2]: https://lkml.org/lkml/2019/12/6/46

---
 arch/um/Kconfig              |  23 +----
 arch/um/Makefile             |   3 +-
 arch/um/kernel/dyn.lds.S     | 170 ----------------------------------
 arch/um/kernel/uml.lds.S     | 115 -----------------------
 arch/um/kernel/vmlinux.lds.S | 175 ++++++++++++++++++++++++++++++++++-
 5 files changed, 172 insertions(+), 314 deletions(-)
 delete mode 100644 arch/um/kernel/dyn.lds.S
 delete mode 100644 arch/um/kernel/uml.lds.S
arch/um/Kconfig +1 -22
index 2a6d04fcb3e91..00927fb7ce67a 100644
@@ -19,6 +19,7 @@ config UML
 	select GENERIC_CLOCKEVENTS
 	select HAVE_GCC_PLUGINS
 	select TTY # Needed for line.c
+	select MODULE_REL_CRCS if MODVERSIONS
 
 config MMU
 	bool
@@ -61,28 +62,6 @@ config NR_CPUS
 
 source "arch/$(HEADER_ARCH)/um/Kconfig"
 
-config STATIC_LINK
-	bool "Force a static link"
-	default n
-	help
-	  This option gives you the ability to force a static link of UML.
-	  Normally, UML is linked as a shared binary.  This is inconvenient for
-	  use in a chroot jail.  So, if you intend to run UML inside a chroot,
-	  you probably want to say Y here.
-	  Additionally, this option enables using higher memory spaces (up to
-	  2.75G) for UML.
-
-config LD_SCRIPT_STATIC
-	bool
-	default y
-	depends on STATIC_LINK
-
-config LD_SCRIPT_DYN
-	bool
-	default y
-	depends on !LD_SCRIPT_STATIC
-	select MODULE_REL_CRCS if MODVERSIONS
-
 config HOSTFS
 	tristate "Host filesystem"
 	help
arch/um/Makefile +1 -2
index d2daa206872da..ec8af28daf051 100644
@@ -117,8 +117,7 @@ archheaders:
 archprepare:
 	$(Q)$(MAKE) $(build)=$(HOST_DIR)/um include/generated/user_constants.h
 
-LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
-LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
+LINK-y += -Wl,-rpath,/lib $(call cc-option, -no-pie)
 
 CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
 	$(call cc-option, -fno-stack-protector,) \
arch/um/kernel/dyn.lds.S deleted +0 -170

170 lines not on this page · raw message

arch/um/kernel/uml.lds.S deleted +0 -115

115 lines not on this page · raw message

arch/um/kernel/vmlinux.lds.S +170 -5

178 lines not on this page · raw message

Signature · 7 lines
2.24.0.393.g34dc348eaf-goog


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#1 lore raw

----- Ursprüngliche Mail -----

Quoted 7 lines

Von: "Brendan Higgins" <[email protected]>
An: "Jeff Dike" <[email protected]>, "richard" <[email protected]>, "anton ivanov" <[email protected]>
CC: "Johannes Berg" <[email protected]>, "linux-um" <[email protected]>, "linux-kernel" <[email protected]>, [email protected], "Brendan Higgins" <[email protected]>
Gesendet: Dienstag, 10. Dezember 2019 00:02:48
Betreff: [PATCH v1] uml: remove support for CONFIG_STATIC_LINK

Quoted 7 lines

CONFIG_STATIC_LINK appears to have been broken since before v4.20. It doesn't play nice with CONFIG_UML_NET_VECTOR=y:

/usr/bin/ld: arch/um/drivers/vector_user.o: in function `user_init_socket_fds': vector_user.c:(.text+0x430): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

This is nothing serious.

Quoted 5 lines

And it seems to break the ptrace check:

Checking that ptrace can change system call numbers...check_ptrace :
child exited with exitcode 6, while expecting 0; status 0x67f
[1] 126822 abort ./linux mem=256M

Didn't we fix that already?

Quoted 7 lines

(Apparently, a patch was recently discussed that fixes this - around v5.5-rc1[1] - but the fact that this was broken for over a year remains.)

According to Anton, PCAP throws even more warnings, and the resulting binary isn't really even static anyway, so there is really no point in keeping this config around[2].

What?
Anton, please explain. Why is it not static when build with CONFIG_STATIC_LINK?

Thanks,
//richard

maintainer
#2 lore raw
Quoted 18 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 7 lines

Von: "Brendan Higgins" <[email protected]>
An: "Jeff Dike" <[email protected]>, "richard" <[email protected]>, "anton ivanov" <[email protected]>
CC: "Johannes Berg" <[email protected]>, "linux-um" <[email protected]>, "linux-kernel" <[email protected]>, [email protected], "Brendan Higgins" <[email protected]>
Gesendet: Dienstag, 10. Dezember 2019 00:02:48
Betreff: [PATCH v1] uml: remove support for CONFIG_STATIC_LINK

Quoted 7 lines

CONFIG_STATIC_LINK appears to have been broken since before v4.20. It doesn't play nice with CONFIG_UML_NET_VECTOR=y:

/usr/bin/ld: arch/um/drivers/vector_user.o: in function `user_init_socket_fds': vector_user.c:(.text+0x430): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

This is nothing serious.

Quoted 7 lines
Quoted 5 lines

And it seems to break the ptrace check:

Checking that ptrace can change system call numbers...check_ptrace :
child exited with exitcode 6, while expecting 0; status 0x67f
[1] 126822 abort ./linux mem=256M

Didn't we fix that already?

Yes we did - I commented on this.

Quoted 11 lines
Quoted 8 lines

(Apparently, a patch was recently discussed that fixes this - around v5.5-rc1[1] - but the fact that this was broken for over a year remains.)

According to Anton, PCAP throws even more warnings, and the resulting binary isn't really even static anyway, so there is really no point in keeping this config around[2].

What?
Anton, please explain. Why is it not static when build with CONFIG_STATIC_LINK?

LIBC itself tries to dynamic load stuff internally.

It is beyond our control and it claims that it will work only on EXACTLY the same version of libc library as the one used for static link.

So you get a not-exactly static binary which is not properly moveable between systems.

This is specifically in the name resolution, etc parts of libc which all of: pcap, vector, vde, etc rely on.

Another alternative is to turn off static specifically for those.

Further to this - any properly written piece of networking code which uses the newer functions for name/service resolution will have the same problem. You can be static only if you do everything "manually" the old way.

Quoted 9 lines

Thanks,
//richard

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 8 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
maintainer
#3 lore raw
Quoted 46 lines · Anton Ivanov
Quoted 18 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 7 lines

Von: "Brendan Higgins" <[email protected]>
An: "Jeff Dike" <[email protected]>, "richard" <[email protected]>, "anton ivanov" <[email protected]>
CC: "Johannes Berg" <[email protected]>, "linux-um" <[email protected]>, "linux-kernel" <[email protected]>, [email protected], "Brendan Higgins" <[email protected]>
Gesendet: Dienstag, 10. Dezember 2019 00:02:48
Betreff: [PATCH v1] uml: remove support for CONFIG_STATIC_LINK

Quoted 7 lines

CONFIG_STATIC_LINK appears to have been broken since before v4.20. It doesn't play nice with CONFIG_UML_NET_VECTOR=y:

/usr/bin/ld: arch/um/drivers/vector_user.o: in function `user_init_socket_fds': vector_user.c:(.text+0x430): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

This is nothing serious.

Quoted 7 lines
Quoted 5 lines

And it seems to break the ptrace check:

Checking that ptrace can change system call numbers...check_ptrace :
child exited with exitcode 6, while expecting 0; status 0x67f [1]    126822 abort      ./linux mem=256M

Didn't we fix that already?

Yes we did - I commented on this.

Quoted 11 lines
Quoted 8 lines

(Apparently, a patch was recently discussed that fixes this - around v5.5-rc1[1] - but the fact that this was broken for over a year remains.)

According to Anton, PCAP throws even more warnings, and the resulting binary isn't really even static anyway, so there is really no point in keeping this config around[2].

What?
Anton, please explain. Why is it not static when build with CONFIG_STATIC_LINK?

LIBC itself tries to dynamic load stuff internally.

It is beyond our control and it claims that it will work only on EXACTLY the same version of libc library as the one used for static link.

Quoted 7 lines

So you get a not-exactly static binary which is not properly moveable between systems.

This is specifically in the name resolution, etc parts of libc which all of: pcap, vector, vde, etc rely on.

Another alternative is to turn off static specifically for those.

Further to this - any properly written piece of networking code which uses the newer functions for name/service resolution will have the same problem. You can be static only if you do everything "manually" the old way.

The offending piece of code is the glibc implementation of getaddrinfo().

If you use it and link static the resulting binary is not really static.

Quoted 12 lines
Quoted 10 lines

Thanks,
//richard

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 8 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
maintainer
#4 lore raw
Quoted 8 lines · Anton Ivanov
Quoted 4 lines

Further to this - any properly written piece of networking code which uses the newer functions for name/service resolution will have the same problem. You can be static only if you do everything "manually" the old way.

The offending piece of code is the glibc implementation of getaddrinfo().

If you use it and link static the resulting binary is not really static.

However, this (getaddrinfo) really only applies if you use the vector network driver, if you e.g. use only virtio then this particular problem isn't present.

Note sure if we implicitly call getaddrinfo from libpcap, but again, that's just a single driver.

IOW, we could just make CONFIG_STATIC_LINK depend on !VECTOR && !PCAP?

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

maintainer
#5 lore raw
Quoted 11 lines · Johannes Berg
Quoted 8 lines · Anton Ivanov
Quoted 4 lines

Further to this - any properly written piece of networking code which uses the newer functions for name/service resolution will have the same problem. You can be static only if you do everything "manually" the old way.

The offending piece of code is the glibc implementation of getaddrinfo().

If you use it and link static the resulting binary is not really static.

Quoted 8 lines

However, this (getaddrinfo) really only applies if you use the vector network driver, if you e.g. use only virtio then this particular problem isn't present.

Note sure if we implicitly call getaddrinfo from libpcap, but again, that's just a single driver.

IOW, we could just make CONFIG_STATIC_LINK depend on !VECTOR && !PCAP?

+1

We also need to add VDE (wonder if anyone still uses that).

We will need to add XDP when I finish it. If memory servces me right, libelf or libbpf has the same lovely features as NSS.

This is not just NSS - it is creeping in with a lot of new libraries. Sometimes the libc guys fix that. For example, librt was like that when I started working on epoll and vector IO.

Sometimes (as in the NSS case) they don't. So the static build containing those will be broken and we are better off making it conflict for those options.

Quoted 9 lines

johannes

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/
#6 lore raw
Quoted 31 lines · Anton Ivanov
Quoted 11 lines · Johannes Berg
Quoted 8 lines · Anton Ivanov
Quoted 4 lines

Further to this - any properly written piece of networking code which uses the newer functions for name/service resolution will have the same problem. You can be static only if you do everything "manually" the old way.

The offending piece of code is the glibc implementation of getaddrinfo().

If you use it and link static the resulting binary is not really static.

Quoted 8 lines

However, this (getaddrinfo) really only applies if you use the vector network driver, if you e.g. use only virtio then this particular problem isn't present.

Note sure if we implicitly call getaddrinfo from libpcap, but again, that's just a single driver.

IOW, we could just make CONFIG_STATIC_LINK depend on !VECTOR && !PCAP?

+1

We also need to add VDE (wonder if anyone still uses that).

We will need to add XDP when I finish it. If memory servces me right, libelf or libbpf has the same lovely features as NSS.

Quoted 7 lines

This is not just NSS - it is creeping in with a lot of new libraries. Sometimes the libc guys fix that. For example, librt was like that when I started working on epoll and vector IO.

Sometimes (as in the NSS case) they don't. So the static build containing those will be broken and we are better off making it conflict for those options.

No strong opinions from me. I am more than happy to submit a new patch that adds the negative dependencies.

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#7 lore raw
In reply to Anton Ivanov

----- Ursprüngliche Mail -----

Quoted 14 lines

Von: "anton ivanov" <[email protected]>

Quoted 13 lines

LIBC itself tries to dynamic load stuff internally.

It is beyond our control and it claims that it will work only on EXACTLY the same version of libc library as the one used for static link.

So you get a not-exactly static binary which is not properly moveable between systems.

This is specifically in the name resolution, etc parts of libc which all
of: pcap, vector, vde, etc rely on.

Another alternative is to turn off static specifically for those.

Quoted 8 lines
Quoted 4 lines

Further to this - any properly written piece of networking code which uses the newer functions for name/service resolution will have the same problem. You can be static only if you do everything "manually" the old way.

The offending piece of code is the glibc implementation of getaddrinfo().

If you use it and link static the resulting binary is not really static.

glibc tries to load NSS and NIS stuff, yes. But what is the problem?

The goal of CONFIG_STATIC_LINK is that you can run UML without dependencies, this used to work since ever. Lately it broke, but hey, let's fix it. I have tons of old statically linked UML systems on my disk which I can just run because they don't depend on specific libs.

Thanks,
//richard

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

A message that is not in the archive (sent off-list or not yet received): DM6PR10MB3225EB0C204572F8D39C0ED5E2550@DM6PR10MB3225.namprd10.prod.outlook.com

#9 lore raw

Fixed up version without html...
Um what is broken, uml seems to be working with the old stack and static linking.

I saw a comment that the vector io stuff breaks uml on static link,
but I was just running one without vector io, I had the pcap library linked in instead. It was up for about 3 days when I rebooted from mconsole 'cad'
It would seem simplest to just mark vector io as !STATIC in the config... I was running 5.4.2 with a pretty close to defconfig

I had to twiddle the uml pcap a little to deconflict the headers, and make sure pcap was not linking to dbus.
I have not looked into vector io too closely I seemed to remember it was using host getaddrinfo the only thing in uml doing so I think it was pulling in the glibc, so-so dynamically link networking even when told not to... and that was breaking the startup process by changing memory maps behind the programs back or some such and then segfaulting the process much like the "we will implement async io in userspace behind the processes back" did back in the day.

I would expect it to be possible to remove the getaddrinfo or use kernel functions.
It does not seem to have much in the way of comments, and I don't understand what it is trying to do.
Why would a network protocol need to lookup "protocol/ip address/port num" sets in userspace? it should just be passing everything somewhere... Is it trying to do dynamic routing of the packets to different transports?

Slight confused but still running,

Jim McMechan
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

maintainer
#10 lore raw
Quoted 9 lines · James McMechan

Fixed up version without html...
Um what is broken, uml seems to be working with the old stack and static linking.

I saw a comment that the vector io stuff breaks uml on static link,
but I was just running one without vector io, I had the pcap library linked in instead. It was up for about 3 days when I rebooted from mconsole 'cad'
It would seem simplest to just mark vector io as !STATIC in the config... I was running 5.4.2 with a pretty close to defconfig

Quoted 4 lines

I had to twiddle the uml pcap a little to deconflict the headers, and make sure pcap was not linking to dbus.
I have not looked into vector io too closely I seemed to remember it was using host getaddrinfo the only thing in uml doing so I think it was pulling in the glibc, so-so dynamically link networking even when told not to... and that was breaking the startup process by changing memory maps behind the programs back or some such and then segfaulting the process much like the "we will implement async io in userspace behind the processes back" did back in the day.

I would expect it to be possible to remove the getaddrinfo or use kernel functions.

If you just try to do 1:1 replacement with the legacy functions you stop being v6 compliant. You after that need to go through quite a lot of hoops and extra code to get that back.

You cannot use kernel functions - this is on the host userspace side of UML.

Quoted 3 lines

It does not seem to have much in the way of comments, and I don't understand what it is trying to do.
Why would a network protocol need to lookup "protocol/ip address/port num" sets in userspace? it should just be passing everything somewhere... Is it trying to do dynamic routing of the packets to different transports?

It is using shared code for (at present) tap (two forms - one optimized for throughput, one using a tap/socket pair optimized for packets per second), raw sockets, gre, l2tpv3 (both raw and over udp) and one flavour unix domain sockets.

Both gre and l2tpv3 support v4 and v6.

While it is possible to replace getaddrinfo with a sequence of gethostbyname, etc it will:

1. Grow the size of the code by at least 100 lines if not more. If I take care of all corner cases which getaddrinfo() does - more.

2. Defeat one of the purposes of the exercise - to make it easy to add new socket transports.

3. There is no guarantee that the glibc guys will not make gethostbyname and friends fallback to getaddrinfo internally one day (in fact I am surprised they have not done it yet).

Quoted 5 lines

Slight confused but still running,

Jim McMechan

Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/