Program cannot run when specify `-zcommon-page-size=2097152` option to lld

Hi all!

When I passed the “-zcommon-page-size=2097152” and “-zmax-page-size=2097152” options to the linker, the program I got didn’t work.

There is my build command.

clang -fuse-ld=lld -Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-size=2097152 -o test test.c
./test

It reports

“error while loading shared libraries: cannot apply additional memory protection after relocation: Cannot allocate memory.”

I don’t know why there’s such a problem. Any reply is appreciated!

There is a simple example reproduction:

Thanks a lot.

COMMONPAGESIZE is pretty much only used to decide the size of PT_GNU_RELRO section. I have some notes at Explain GNU style linker options | MaskRay “-z relro”.

[ELF] Align the end of PT_GNU_RELRO associated PT_LOAD to a common-page-size boundary by MaskRay · Pull Request #66042 · llvm/llvm-project · GitHub will be part of LLD 18 and -z common-page-size=2097152 should work. “Before LLD 18, there is an issue that runtime_page_size < common-page-size does not work.”

1 Like

Thank you very much! It works.