Skip to content

build: Drop the use of patchelf(1) - #942

Merged
debarshiray merged 2 commits into
containers:mainfrom
debarshiray:wip/rishi/drop-patchelf
Dec 9, 2021
Merged

debarshiray merged 2 commits into
containers:mainfrom
debarshiray:wip/rishi/drop-patchelf

Conversation

@debarshiray

@debarshiray debarshiray commented Dec 1, 2021 •

Copy link
Copy Markdown
Member

Some downstream distributors like RHEL don't have patchelf(1). Relying
on patchelf(1) during the build will make it difficult for such
downstreams to distribute Toolbox.

Fortunately, the path of the dynamic linker (ie., PT_INTERP) is
hardcoded in the ABI specification of each architecture [1]. This means
that Toolbox's build system can keep it's own architecture to dynamic
linker mapping, and specify it during the build through the GNU ld
linker's --dynamic-linker flag, as opposed to using a tool like
patchelf(1) to change the path of the dynamic linker in the built
binary to the one inside /run/host. Currently, the list of
architectures covers the ones that Fedora builds for.

[1] https://sourceware.org/glibc/wiki/ABIList

debarshiray added a commit to debarshiray/toolbox that referenced this pull request Dec 1, 2021
The subsequent commit will further bump the minimum Meson version to
0.58.0. This will make it easier to read.

containers#942
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Dec 1, 2021
@debarshiray
debarshiray force-pushed the wip/rishi/drop-patchelf branch from ffb8270 to f8629dc Compare December 1, 2021 03:30
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@martymichal martymichal added 2. Build System Issue is related to the build system 3. Enhancement Improvement to an existing feature 6. Major Change May cause breakage labels Dec 1, 2021
@debarshiray

Copy link
Copy Markdown
Member Author

recheck

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@martymichal martymichal added this to the Release 0.1.0 milestone Dec 4, 2021
The subsequent commit will further bump the minimum Meson version to
0.58.0. This will make it easier to read.

containers#942
@debarshiray

debarshiray commented Dec 8, 2021 •

Copy link
Copy Markdown
Member Author

We have a bootstrapping problem here.

The build fails because go build -ldflags "-extldflags '-Wl,-dynamic-path,...'" specifies a dynamic linker under /run/host, which doesn't exist during the build because /run/host is created by the build.

debarshiray added a commit to debarshiray/toolbox that referenced this pull request Dec 9, 2021
Some downstream distributors like RHEL don't have patchelf(1). Relying
on patchelf(1) during the build will make it difficult for such
downstreams to distribute Toolbox.

containers#942
@debarshiray
debarshiray force-pushed the wip/rishi/drop-patchelf branch from f8629dc to 4f27ef0 Compare December 9, 2021 00:24
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray

Copy link
Copy Markdown
Member Author

We have a bootstrapping problem here.

The build fails because go build -ldflags "-extldflags '-Wl,-dynamic-path,...'"
specifies a dynamic linker under /run/host, which doesn't exist during the
build because /run/host is created by the build.

Turns out that the linker flag is -dynamic-linker, not -dynamic-path. With the correctly spelled flag, the toolchain doesn't bother checking if the path to the dynamic linker actually exists, and the build proceeds as expected. Phew!

We still need to double-check if the path to the dynamic linker is specified correctly for each architecture.

Some downstream distributors like RHEL don't have patchelf(1). Relying
on patchelf(1) during the build will make it difficult for such
downstreams to distribute Toolbox.

Fortunately, the path of the dynamic linker (ie., PT_INTERP) is
hardcoded in the ABI specification of each architecture [1]. This means
that Toolbox's build system can keep it's own architecture to dynamic
linker mapping, and specify it during the build through the GNU ld
linker's --dynamic-linker flag, as opposed to using a tool like
patchelf(1) to change the path of the dynamic linker in the built
binary to the one inside /run/host. Currently, the list of
architectures covers the ones that Fedora builds for.

[1] https://sourceware.org/glibc/wiki/ABIList

containers#942
@debarshiray
debarshiray force-pushed the wip/rishi/drop-patchelf branch from 4f27ef0 to 8dd7ee4 Compare December 9, 2021 12:33
@softwarefactory-delete-me

Copy link
Copy Markdown

Build succeeded.

@martymichal

Copy link
Copy Markdown
Member

We have a bootstrapping problem here.
The build fails because go build -ldflags "-extldflags '-Wl,-dynamic-path,...'"
specifies a dynamic linker under /run/host, which doesn't exist during the
build because /run/host is created by the build.

Turns out that the linker flag is -dynamic-linker, not -dynamic-path. With the correctly spelled flag, the toolchain doesn't bother checking if the path to the dynamic linker actually exists, and the build proceeds as expected. Phew!

We still need to double-check if the path to the dynamic linker is specified correctly for each architecture.

But for the final binary to be operational the /run/host symlink to / has to exist, right? For that reason the build also has to adjusted as in #840 the created binary is used to generate the completion files.

@debarshiray

Copy link
Copy Markdown
Member Author

But for the final binary to be operational the /run/host symlink to / has to
exist, right?

Yes.

For that reason the build also has to adjusted as in #840 the created
binary is used to generate the completion files.

I haven't looked at #840 - we'll see when we get to that. Currently, we urgently need to roll a release, and we can't do that as long as we require patchelf(1) for the build.

@debarshiray
debarshiray merged commit 8dd7ee4 into containers:main Dec 9, 2021
@debarshiray
debarshiray deleted the wip/rishi/drop-patchelf branch December 9, 2021 14:04
debarshiray added a commit to containers/containertoolbx.org that referenced this pull request Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. Build System Issue is related to the build system 3. Enhancement Improvement to an existing feature 6. Major Change May cause breakage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants