Skip to content

opcache.huge_code_pages: "program section not found" on musl (Alpine), wrong base address from dl_iterate_phdr #25742

Backlog

Description

@krzysztofsurdy

Description

With opcache.huge_code_pages=1, PHP 8.5 on musl (Alpine) logs a warning on every process start and never moves the text segment to huge pages. The same config is silent on 8.4 and on the Debian (glibc) image.

docker run --rm php:8.5-cli-alpine php -d opcache.enable_cli=1 -d opcache.huge_code_pages=1 -r 'echo "done\n";'

Resulted in this output:

Warning: Zend OPcache: opcache.huge_code_pages: program section not found in Unknown on line 0
done

But I expected this output instead:

done

php:8.5-cli (Debian) prints just done, and on 8.4 the remap worked fine on Alpine (AnonHugePages covered the whole text segment).

Cause

accel_dl_iterate_phdr_callback() (added in 0ee7732, GH-19388) takes the first dl_iterate_phdr() entry with an empty dlpi_name as
the main executable. That's how glibc reports it, but musl gives the main program its path as name, and the only entry with an empty
name is the vDSO. Small test on Alpine:

static int cb(struct dl_phdr_info *i, size_t s, void *d) {
  printf("name=\"%s\" addr=%#lx\n", i->dlpi_name, (unsigned long)i->dlpi_addr);
  return 0;
}
main() at 0xaaaac03f0880
name="/t" addr=0xaaaac03f0000
name="/lib/ld-musl-aarch64.so.1" addr=0xffffa2275000
name="" addr=0xffffa2333000

So the section headers from /proc/self/exe get offset by the vDSO base, and none of them contains accel_find_program_section. Debug log (opcache.log_verbosity_level=4):

Debug considering section 0000ffffaeaa5000-0000ffffaeaa5000 vs 0000aaaada7b7e60
Debug considering section 0000ffffaeaa5270-0000ffffaeaa5294 vs 0000aaaada7b7e60
...
Warning: Zend OPcache: opcache.huge_code_pages: program section not found

/proc/self/maps from a separate run (ASLR, so addresses differ) shows php at 0xaaaa... and [vdso] at 0xffff....

Possible fix

Match the object by address, not by name. Untested sketch:

static int accel_dl_iterate_phdr_callback(struct dl_phdr_info *info, size_t size, void *data) {
        uintptr_t target = (uintptr_t)accel_dl_iterate_phdr_callback;
        for (ElfW(Half) i = 0; i < info->dlpi_phnum; i++) {
                const ElfW(Phdr) *ph = &info->dlpi_phdr[i];
                uintptr_t start = info->dlpi_addr + ph->p_vaddr;
                if (ph->p_type == PT_LOAD && target >= start && target < start + ph->p_memsz) {
                        *((uintptr_t*)data) = info->dlpi_addr;
                        return 1;
                }
        }
        return 0;
}

This works the same on glibc, where the main program is the entry that contains the address anyway.

PHP Version

PHP 8.5.13 (cli) (built: Nov 19 2026 14:30:21) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.13, Copyright (c), by Zend Technologies

php@sha256:b9d7db51a2b83c41420ba04de0b90e6078d4b6440e5cc480fc4dc51b18e0b6db.

Operating System

Alpine Linux 3.24 (musl), official php:8.5-cli-alpine image. Seen on aarch64 and in our production pods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions