Date: Tue, 13 Aug 2019 11:45:43 +0000 From: Fangrui Song <i@...kray.me> To: Micha Nelissen <nelissen.micha@...il.com> Cc: musl@...ts.openwall.com Subject: Re: Re: size of executable On 2019-08-13, Micha Nelissen wrote: >On 12-08-2019 20:23, Rich Felker wrote: >>On Mon, Aug 12, 2019 at 11:16:39AM -0700, Khem Raj wrote: >>>On Mon, Aug 12, 2019 at 10:19 AM Rich Felker <dalias@...c.org> wrote: >>>>On Mon, Aug 12, 2019 at 05:55:28PM +0100, Jorge Almeida wrote: >>>>>On Mon, Aug 12, 2019 at 5:48 PM Jorge Almeida <jjalmeida@...il.com> wrote: >>>>>>I get 16768 bytes (not stripped) and 12324 (stripped). >>>> >>>>This is a binutils regression from a dubious anti-ROP feature, -z >>>>separate-code. Add -Wl,-z,noseparate-code and it will go away. >>> >>>is this still so with latest release as well. >> >>The breakage that caused separate-code to crash at runtime was fixed >>between 2.31 and 2.32, but the size and performance regression >>remains. With separate-code, a couple extra pages of memory and disk >>are needed, with corresponding runtime cost to mmap them properly. >> >>All to avoid ROP gadgets, when every single dynamic-linked program has >>a nice ROP gadget named "system" (among many others) in it... > >I'm curious. Jorge reports that the executable goes from 12k to 4k. >That suggests two pages saved? But if I look at documentation for this >separate-code option, then it says to allocate a separate code PT_LOAD >segment. (PT_LOAD just means loadable?) That would suggest up to 4k >more usage, not 8k right? One extra page necessary. Are by default >rodata and code combined but with separate-code those are separated? >Or something more happening? binutils 2.31 includes a change "ld: Add --enable-separate-code". This is enabled by default for Linux x86. You can compile a trivial program with -z separate-code and -z noseparate-code, run readelf -l and compare the results. -z noseparate-code LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0007d8 0x0007d8 R E 0x1000 LOAD 0x000e18 0x0000000000001e18 0x0000000000001e18 0x000210 0x000218 RW 0x1000 -z separate-code LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000530 0x000530 R 0x1000 LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x0001cd 0x0001cd R E 0x1000 LOAD 0x002000 0x0000000000002000 0x0000000000002000 0x000148 0x000148 R 0x1000 LOAD 0x002e18 0x0000000000003e18 0x0000000000003e18 0x000210 0x000218 RW 0x1000 -z separate-code has two more PT_LOAD segments. What is bad is that the two PT_LOAD segments have aligned p_offset: diff -u =(ld.bfd --verbose -z noseparate-code) =(ld.bfd --verbose -z separate-code) + . = ALIGN(CONSTANT (MAXPAGESIZE)); + . = ALIGN(CONSTANT (MAXPAGESIZE)); + /* Adjust the address for the rodata segment. We want to adjust up to + the same address within the page on the next page up. */ + . = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1))); This disables an important size optimization (I have some description in https://reviews.llvm.org/D64906)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.