Skip to content

don't explicitly --enable-pic for ZTS - #1692

Merged
tianon merged 2 commits into
docker-library:masterfrom
henderkes:master
Oct 12, 2026
Merged

tianon merged 2 commits into
docker-library:masterfrom
henderkes:master

Conversation

@henderkes

@henderkes henderkes commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

When libtool sees --enable-pic, it goes through flags, adds -fpic if not supplied and removes -fpie from cflags, putting it in pie_flags instead, which aren't passed to the compilation. This results in __PIC__ being defined but __PIE__ undefined, causing initial-exec to be selected instead of local-exec. Every tls variable access requires 2 instructions instead of one.

# Initial-exec: load offset from GOT, then load TLS value
movq tls_cache@gottpoff(%rip), %rax
movq %fs:(%rax), %rax

# Local-exec: offset encoded directly in the instruction
movq %fs:tls_cache@tpoff, %rax

When not passing --enable-pic, our cflags which contain -fpic fpie anyways are honoured and php selects local-exec.

Comment thread Dockerfile-linux.template
Comment on lines +382 to 385
{{ ) else ( -}}
# Forcing PIC also removes -fpie from executable objects, preventing local-exec TLS.
# So do not --enable-pic
{{ ) end -}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You put some good detail in this PR description so I think we should link to it, and I think we can go a little bit tighter on the note:

Suggested change
{{ ) else ( -}}
# Forcing PIC also removes -fpie from executable objects, preventing local-exec TLS.
# So do not --enable-pic
{{ ) end -}}
{{ ) else ( -}}
# no --enable-pic; forcing PIC also removes -fpie from executable objects, preventing local-exec TLS: https://github.com/docker-library/php/pull/1692
{{ ) end -}}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied the suggestion and updated the PR comment.

I will also upstream a fix to libtool, but it won't land in php 8.6.

Co-authored-by: Tianon Gravi <admwiggin@gmail.com>
@tianon
tianon merged commit 9dac3d0 into docker-library:master Oct 12, 2026
96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants