News for hackers. Stuff that matters.
Re:32-bit x86 Position Independent Code – It's That Bad by atesti on Wednesday April 15, 2015 @01:25AM (#9379040)
I always wondered why Linux can't just use the same thing as windows for DLLs: Instead of PIC, a big tables of places to patch with the final position.

It looks really terrible to lose one precious register and have all this PIC overhead.

I don't use mono's ahead of time compilation because it also creates PIC. The JIT has one register more available. But I haven't measured it yet

Re:32-bit x86 Position Independent Code – It's That Bad by zurn on Wednesday April 15, 2015 @06:03AM (#9379903)
Linux did this before, but moved to PIC around 1995 as part of the a.out->ELF transition.

ELF actually supports (and always did) non-PIC code on x86 Linux in shared libs, ld.so will do fixups to the code on the fly. See http://eli.thegreenplace.net/2011/11/03/position-independent...

Re:32-bit x86 Position Independent Code – It's That Bad by JoshTriplett on Wednesday April 15, 2015 @01:29AM (#9379049)
> Instead of PIC, a big tables of places to patch with the final position.

Among other things, because that means the text section has to be writeable, and can't have a shared mapping across processes unless it's mapped in the same place in every process, which breaks address-space layout randomization (ASLR).

Re:32-bit x86 Position Independent Code – It's That Bad by atesti on Wednesday April 15, 2015 @01:41AM (#9379076)
On Windows, one can decide a default position for each DLL and if one is lucky, there is space available in that area of the virtual address space. Otherwise the loader needs to do the relocation work and modify pages and make them writeable temporarily.

If multiple processes load the same DLL and the default location happens to be chosen well and there is virtual address space in every process, then the linker can simply share the DLL.

That's how I think it was before ASLR came around.

I think Windows removes the writeable-flag again after relocating.

For the area I described (Mono's JIT vs. Mono's ahead of time compilation as PIC .so-file) I personally don't care that much for ASLR, because it's a managed language and because of specific circumstances of that project.

Re:32-bit x86 Position Independent Code – It's That Bad by JoshTriplett on Wednesday April 15, 2015 @02:03AM (#9379145)
Linux had a similar mechanism, "prelink", which also completely broke with ASLR.
Re:32-bit x86 Position Independent Code – It's That Bad by userbinator on Wednesday April 15, 2015 @06:56AM (#9380050)
Windows has ASLR too (since Vista) and it works with existing DLLs. Only pages which contain relocations can't be shared, which in practice means only code that accesses global data (including calls through the import table to other modules.) All the other pages can be.

The whole process image is writable when the loader is running - else how could it load the code into memory? :-) Section attributes are applied after loading.

Re:32-bit x86 Position Independent Code – It's That Bad by dblohm7 on Wednesday April 15, 2015 @02:26PM (#9383034)
Windows doesn't store those thunks in the text section. They're in the .idata section instead.
Re:32-bit x86 Position Independent Code – It's That Bad by yoklov on Wednesday April 15, 2015 @09:02AM (#9380646)
Off topic, but does anybody know if there's a way to turn off ASLR e.g. while debugging (honestly, i'd be interested if you can do this on any platform)? I'm pretty confident the answer is no, but it can really be a pain sometimes...
Re:32-bit x86 Position Independent Code – It's That Bad by tekacs on Wednesday April 15, 2015 @01:03PM (#9382394)
Either the linker, or GDB (or your debugger) can disable it for you. Under GDB it's controlled by the setting disable-randomization (defaults to false).
Re:32-bit x86 Position Independent Code – It's That Bad by detaro on Wednesday April 15, 2015 @09:07AM (#9380676)
/proc/sys/kernel/randomize_va_space on Linux?
Re:32-bit x86 Position Independent Code – It's That Bad by rwallace on Wednesday April 15, 2015 @12:12PM (#9381950)
On Windows, the linker has an option to do that.
Re:32-bit x86 Position Independent Code – It's That Bad by zurn on Thursday April 16, 2015 @01:31AM (#9386030)
setarch x86_64 --addr-no-randomize myprogram args...

(or -R for short)

Re:32-bit x86 Position Independent Code – It's That Bad by kazinator on Wednesday April 15, 2015 @10:36AM (#9381221)
Windows DLL's don't have features such as the executable overriding symbols in the attached library.

In fact, if you call LoadLibrary at runtime, there is no symbol resolution; you have to look up symbols yourself using GetProcAddress.

Under dlopen, symbol resolution takes place; it can change the destinations of function calls.

Re:32-bit x86 Position Independent Code – It's That Bad by userbinator on Wednesday April 15, 2015 @10:59AM (#9381373)
Under dlopen, symbol resolution takes place; it can change the destinations of function calls.

I'm probably a bit biased since I'm rather used to Windows' explicit import-export system, but having function calls change just because a library was loaded sounds like an opportunity for some extremely confusing bugs.