Skip to contentSkip to conversation

package/tini: compile executable static

PATCH Superseded Simon Rowe 4 participants 9 messages Nov 20, 2019 – Dec 3, 2019

lore
Share & tools
lore

Simon Rowe

author
#0 lore raw

PATCH 1/1 package/tini: compile executable static

tini is intended to be used as the init process within containers and therefore needs to be independent of the C runtime library.

---
 package/tini/tini.mk | 1 +
 1 file changed, 1 insertion(+)
package/tini/tini.mk +1 -0
index 5dd9877..986e612 100644
@@ -10,6 +10,7 @@ TINI_LICENSE = MIT
 TINI_LICENSE_FILES = LICENSE
 
 TINI_CFLAGS = $(TARGET_CFLAGS) \
+	-static \
 	-DTINI_VERSION=\"$(TINI_VERSION)\" \
 	-DTINI_GIT=\"\"
 
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 package/tini: compile executable static

Simon, All,

On 2019-11-20 13:09 +0000, Simon Rowe spake thusly:

Quoted 13 lines

tini is intended to be used as the init process within containers and therefore needs to be independent of the C runtime library.

---
 package/tini/tini.mk | 1 +
 1 file changed, 1 insertion(+)
package/tini/tini.mk +0 -0
index 5dd9877..986e612 100644

package/tini/tini.mk TINI_LICENSE = MIT · line 13

Quoted 4 lines
package/tini/tini.mk +1 -0
@@ -10,6 +10,7 @@ TINI_LICENSE = MIT
 TINI_LICENSE_FILES = LICENSE
 
 TINI_CFLAGS = $(TARGET_CFLAGS) \
+	-static \

That can't work as-is, because this would break with BR2_SHARED_LIBS=y, in which case only shared libraries are available.

Furthermore, the commit message introducing tini explicitly states "it is not necessary to compile Tini statically for many non-docker container environments". So, what has changed since then?

Besides, I would expect that the init process of a container would be provided inside the container, not come from the host system. As such, the init system of the container can be dynamically linked with the runtime of the container itself.

In any case, this patch is incorrect in the shared-only setup, so I marked it as rejected for now. If you can provide a beter way to do what you need, then we can revisit it later with a different implementation (and more explanations on how this is used in the wild).

Regards,
Yann E. MORIN.

Quoted 10 lines
package/tini/tini.mk +0 -0
 	-DTINI_VERSION=\"$(TINI_VERSION)\" \
 	-DTINI_GIT=\"\"
 
Signature · 6 lines
1.8.3.1

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

PATCH 1/1 package/tini: compile executable static

Quoted 2 lines · Yann E. MORIN

That can't work as-is, because this would break with BR2_SHARED_LIBS=y, in which case only shared libraries are available.

Thanks for pointing this out.

Quoted 8 lines

Furthermore, the commit message introducing tini explicitly states "it is not necessary to compile Tini statically for many non-docker container environments". So, what has changed since then?

Besides, I would expect that the init process of a container would be provided inside the container, not come from the host system. As such, the init system of the container can be dynamically linked with the runtime of the container itself.

Passing --init to "docker run" takes whatever the executable docker-init in the OS filesystem is and uses it as the process for pid 1 in the container. If the OS is buildroot and the container uses glibc that doesn't work.

Quoted 4 lines

In any case, this patch is incorrect in the shared-only setup, so I marked it as rejected for now. If you can provide a beter way to do what you need, then we can revisit it later with a different implementation (and more explanations on how this is used in the wild).

I can add the static linking as an option. I would have done so but it was suggested here

http://lists.busybox.net/pipermail/buildroot/2017-October/204974.html

that an init should always be statically linked.

In summary I can make this optional and mutually exclusive with BR2_SHARED_LIBS, would that be acceptable?

Simon

#3 lore raw

PATCH 1/1 package/tini: compile executable static

Quoted 2 lines · Simon Rowe

If the OS is buildroot and the container uses glibc that doesn't work.

I meant to say "If buildroot uses musl and the container uses glibc ..."

Simon

#4 lore raw

PATCH 1/1 package/tini: compile executable static

In reply to Simon Rowe
Quoted 6 lines · Simon Rowe
Quoted 2 lines · Yann E. MORIN

That can't work as-is, because this would break with BR2_SHARED_LIBS=y, in which case only shared libraries are available.

Thanks for pointing this out.

Well, actually, we really should keep at least libc.a around even if
BR2_SHARED_LIBS=y, because some packages (with no dependencies, and that don't use NSS - like tini) may still want to link statically.

In fact, I think we already keep libc.a around in all possible cases even if
BR2_SHARED_LIBS=y, so I think this patch will work as is...

Quoted 3 lines
Quoted 3 lines

Furthermore, the commit message introducing tini explicitly states "it is not necessary to compile Tini statically for many non-docker container environments". So, what has changed since then?

Maybe Christian can explain? I vaguely remember that discussion from a year
ago. IIRC, Christian initially did exactly this: link tini statically, always. But then it turned out not to be needed.

Quoted 2 lines
Quoted 2 lines

Besides, I would expect that the init process of a container would be provided inside the container, not come from the host system.

No, the point of tini is exactly to avoid using the init inside the container -
either because it's doing too much (e.g. full systemd) or because it doesn't exist (container image with just the application).

Quoted 16 lines
Quoted 3 lines

As such,
the init system of the container can be dynamically linked with the runtime of the container itself.

Passing --init to "docker run" takes whatever the executable docker-init in the OS filesystem is and uses it as the process for pid 1 in the container. If the OS is buildroot and the container uses glibc that doesn't work.

Quoted 4 lines

In any case, this patch is incorrect in the shared-only setup, so I marked it as rejected for now. If you can provide a beter way to do what you need, then we can revisit it later with a different implementation (and more explanations on how this is used in the wild).

I can add the static linking as an option. I would have done so but it was suggested here

Quoted 6 lines

http://lists.busybox.net/pipermail/buildroot/2017-October/204974.html

that an init should always be statically linked.

In summary I can make this optional and mutually exclusive with BR2_SHARED_LIBS, would that be acceptable?

Could you check with BR2_SHARED_LIBS=y and the current patch if it's possible
to build tini for all cases? I.e., external toolchain, internal with musl, glibc, uClibc. If not, then you can make it conditional on !shared like this:

	$(if $(BR2_SHARED_LIBS),,-static)

And of course, we still need an explanation why it is needed after all while
before we thought it wasn't.

Regards,
Arnout

#5 lore raw

PATCH 1/1 package/tini: compile executable static

Quoted 5 lines · Arnout Vandecappelle

Could you check with BR2_SHARED_LIBS=y and the current patch if it's possible
to build tini for all cases? I.e., external toolchain, internal with musl, glibc, uClibc. If not, then you can make it conditional on !shared like this:

	$(if $(BR2_SHARED_LIBS),,-static)

I've run the current patch with the following toolchains

* internal, only shared libraries, musl
* internal, only shared libraries, uClibc
* internal, only shared libraries, glibc
* external, only shared libraries, musl

and tini is built correctly.

Quoted 2 lines

And of course, we still need an explanation why it is needed after all while
before we thought it wasn't.

Does this need an expansion of the commit message or something elsewhere?

Simon

#6 lore raw

PATCH 1/1 package/tini: compile executable static

Quoted 8 lines · Simon Rowe
Quoted 5 lines · Arnout Vandecappelle

? Could you check with BR2_SHARED_LIBS=y and the current patch if it's possible to build tini for all cases? I.e., external toolchain, internal with musl, glibc, uClibc. If not, then you can make it conditional on !shared like this:

????$(if $(BR2_SHARED_LIBS),,-static)

Quoted 8 lines

I've run the current patch with the following toolchains

* internal, only shared libraries, musl
* internal, only shared libraries, uClibc
* internal, only shared libraries, glibc
* external, only shared libraries, musl

and tini is built correctly.

Excellent!

So the patch was OK, just the commit message should be updated.

Quoted 5 lines
Quoted 3 lines

? And of course, we still need an explanation why it is needed after all while before we thought it wasn't.

Does this need an expansion of the commit message or something elsewhere?

Commit message.

Thanks!

Regards,
Arnout

author
#7 lore raw

PATCH v2 1/1 package/tini: compile executable static

In reply to Simon Rowe

One usecase for tini is as the init process for a container which has a single executable and no C runtime library. It therefore needs to be independent of any C runtime library within the container.

Tested with multiple toolchains and BR2_SHARED_LIBS=y.

---
Changes v1 -> v2:
- tested with other toolchains
- expanded reasoning for static linking

---
 package/tini/tini.mk | 1 +
 1 file changed, 1 insertion(+)
package/tini/tini.mk +1 -0
index 5dd9877..986e612 100644
@@ -10,6 +10,7 @@ TINI_LICENSE = MIT
 TINI_LICENSE_FILES = LICENSE
 
 TINI_CFLAGS = $(TARGET_CFLAGS) \
+	-static \
 	-DTINI_VERSION=\"$(TINI_VERSION)\" \
 	-DTINI_GIT=\"\"
 
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v2 1/1 package/tini: compile executable static

Quoted 7 lines · Simon Rowe

One usecase for tini is as the init process for a container which has a single executable and no C runtime library. It therefore needs to be independent of any C runtime library within the container.

Tested with multiple toolchains and BR2_SHARED_LIBS=y.

Applied to master, thanks. I've extended the commit message a bit.

Regards,
Arnout

Quoted 22 lines

---
Changes v1 -> v2:
- tested with other toolchains
- expanded reasoning for static linking

---
 package/tini/tini.mk | 1 +
 1 file changed, 1 insertion(+)
package/tini/tini.mk +1 -0
index 5dd9877..986e612 100644
@@ -10,6 +10,7 @@ TINI_LICENSE = MIT
 TINI_LICENSE_FILES = LICENSE
 
 TINI_CFLAGS = $(TARGET_CFLAGS) \
+	-static \
 	-DTINI_VERSION=\"$(TINI_VERSION)\" \
 	-DTINI_GIT=\"\"