New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 38774 - Support common-page-size=value keyword
Summary: Support common-page-size=value keyword
Status: RESOLVED FIXED
Alias: None
Product: lld
Classification: Unclassified
Component: ELF (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL: https://github.com/ClangBuiltLinux/li...
Keywords:
: 39288 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-08-30 06:30 PDT by Dmitry Golovin
Modified: 2019-05-13 09:08 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s): 360593


Attachments
0001-x86-vdso-drop-implicit-common-page-size-linker-flag.patch (1.76 KB, text/plain)
2018-12-05 14:15 PST, Nick Desaulniers
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Golovin 2018-08-30 06:30:51 PDT
Linux kernel's vdso64.so is compiled with "-Wl,-z,common-page-size=4096" which is not supported by LLD and leads to linker error:

    ld.lld: error: unknown -z value: common-page-size=4096

"common-page-size=value" is not a recognized keyword for LLD, but it is for GNU ld. GNU ld manpage describes this keyword as the following:

    common-page-size=value 
    Set the emulation common page size to value.
Comment 1 Dmitry Golovin 2018-10-14 23:01:31 PDT
*** Bug 39288 has been marked as a duplicate of this bug. ***
Comment 2 Rui Ueyama 2018-10-24 10:59:41 PDT
`-z common-page-size` is awfully under-documented, so I took a look at GNU gold to understand the semantics. It looks like gold its parameter value to adjust segment offsets so that segments with different attributes (e.g. .text and .data) share the same page (which is mapped to memory twice), if I understand it correctly.

In lld, we always round up the end of each segment to the page size. So, it looks like `-z common-page-size` doesn't make sense to be added to lld. We can recognize the flag just to ignore it. But I don't see a reason to really support it.
Comment 3 Nick Desaulniers 2018-10-24 11:18:09 PDT
How does it interact with `-z max-page-size=`? The code we're working with actually sets:

-z max-page-size=4096 -z common-page-size=4096

So maybe it's safe to not use common-page-size when max-page-size would have the same value and using LLD? Or are they unrelated?
Comment 4 Rui Ueyama 2018-10-24 11:28:20 PDT
IIUC, max-page-size affects how segments are aligned in memory. Say, you set max-page-size to 2 MiB. Then all segments are aligned to 2 MiB, so that different segments are mapped to different pages with different page attributes.

If you set max-page-size to 4096, and if the runtime OS does not support 4 Ki pages but only 2 MiB large pages, I believe your executable will fail on load time, because your executable is very likely to contain executable and non-executable segments in the same 2 MiB page at the boundary. But this is perhaps hypothetical because I don't think all operating systems that support large pages support both small and large pages.

Are you fixing the issue for x86-64/i386? If so, max-page-size is set to 4096 already by default, so I believe you can just remove these flags from the linker command line.
Comment 5 Nick Desaulniers 2018-12-05 14:15:17 PST
Created attachment 21197 [details]
0001-x86-vdso-drop-implicit-common-page-size-linker-flag.patch
Comment 6 Nick Desaulniers 2018-12-06 11:12:28 PST
I've submitted the above patch to LKML: https://lkml.org/lkml/2018/12/6/1034

Will close this bug if upstream accepts the patch.
Comment 7 Nick Desaulniers 2018-12-10 09:55:42 PST
Fix landed in Linux 4.20-rc6 

commit ac3e233d29f7f77f28243af0132057d378d3ea58 ("x86/vdso: Drop implicit common-page-size linker flag")

So this flag is still not supported in LLD, but it seems that this will be ok going forward; a break from binutils that makes sense IMO.

Closing this bug.
Comment 8 Nick Desaulniers 2019-05-10 12:44:48 PDT
I believe Peter Smith is implementing this in LLD.
Comment 9 Peter Smith 2019-05-13 09:08:47 PDT
Support for -z common-page-size is in r360593