Skip to content

ELF: Add a -z glibc-228-compat flag for working around an old glibc bug. #133532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: users/pcc/spr/main.elf-add-a-z-glibc-228-compat-flag-for-working-around-an-old-glibc-bug
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lld/ELF/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ struct Config {
bool zCopyreloc;
bool zForceBti;
bool zForceIbt;
bool zGlibc228Compat;
bool zGlobal;
bool zHazardplt;
bool zIfuncNoplt;
Expand Down
1 change: 1 addition & 0 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
ctx.arg.zForceBti = hasZOption(args, "force-bti");
ctx.arg.zForceIbt = hasZOption(args, "force-ibt");
ctx.arg.zGcs = getZGcs(ctx, args);
ctx.arg.zGlibc228Compat = hasZOption(args, "glibc-228-compat");
ctx.arg.zGlobal = hasZOption(args, "global");
ctx.arg.zGnustack = getZGnuStack(args);
ctx.arg.zHazardplt = hasZOption(args, "hazardplt");
Expand Down
13 changes: 13 additions & 0 deletions lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,19 @@ static uint64_t computeFlags(Ctx &ctx, uint64_t flags) {
return PF_R | PF_W | PF_X;
if (ctx.arg.executeOnly && (flags & PF_X))
return flags & ~PF_R;

// The -z glibc-228-compat flag is used for binaries utilizing IFUNCs which
// need to be compatible with glibc versions containing a bug that was fixed
// in commit b5c45e83753b27dc538dff2d55d4410c385cf3a4 which was released in
// version 2.29. The bug causes glibc to mprotect the .text section as RW
// while calling ifunc resolvers in binaries linked with -z notext, leading to
// a SIGSEGV at startup time. By setting the W flag on the executable section
// we work around the bug by avoiding the code path that does the mprotect. It
// is recommended that binaries linked with this flag contain startup code
// (e.g. in .init_array) that remaps the executable section as non-writable.
if (ctx.arg.zGlibc228Compat && !ctx.arg.zText && (flags & PF_X))
return flags | PF_W;

return flags;
}

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.