4 ms·
> 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
by JoshTriplett 12y ago
> 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).
- atesti 12y agoOn 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.
- JoshTriplett 12y agoLinux had a similar mechanism, "prelink", which also completely broke with ASLR.
- userbinator 12y agoWindows 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.
- yoklov 12y agoOff 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...
- detaro 12y ago/proc/sys/kernel/randomize_va_space on Linux?
- rwallace 12y agoOn Windows, the linker has an option to do that.
- tekacs 12y agoEither 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).
- zurn 12y agosetarch x86_64 --addr-no-randomize myprogram args... (or -R for short)
- dblohm7 12y agoWindows doesn't store those thunks in the text section. They're in the .idata section instead.