Senin, 25 Juni 2018

Sponsored Links

CS 3214 Introduction to Computer Systems - ppt download
src: slideplayer.com

In computing, the position-independent code ( PIC ) or the executable-independent position ( PIE ) is the body the machine code, placed somewhere in the main memory, is executed correctly regardless of its absolute address. PICs are commonly used for shared libraries, so the same library code can be loaded in locations in any program address space that will not overlap with other memory usage (for example, other shared libraries). PICs are also used on older computer systems that do not have an MMU, so the operating system can keep applications away from each other even in a single system address space without MMU.

Positional code can be executed in all memory addresses without modification. This differs from the absolute code, which must be loaded at a specific location to function correctly, and locatable load-time code (LTL), where the programmer or programmer modifies the program prior to execution so that it can only run from a specified memory location. Generating position-independent code is often the default behavior for compilers, but they can place restrictions on the use of some language features, such as prohibiting the use of absolute addresses (position-independent code should use relative addressing). Instructions that refer directly to specific memory addresses sometimes execute faster, and replacing them with relatively equivalent addressing instructions can result in slightly slower execution, although modern processors make practical differences negligible.


Video Position-independent code



Histori

In early computers such as IBM System/360 (1965), the code relies on the position: each program is built to be loaded into, and run from, a specific address. Where a multitasking operating system allows multiple jobs to run using a separate program at the same time, the operation should be scheduled in such a way that no two concurrent jobs run programs that require the same load address. For example, both payroll programs and receivable programs built to run at 32K addresses can not be both run at the same time.

IBM DOS/360 (1966) does not have the ability to relocate the program during loading. Sometimes several versions of the program are maintained, each made for a different load address. Program-specific classes, called self-relocation programs, are coded to relocate themselves after loading. IBM OS/360 (1966) relocated executable programs when loaded into memory. Only one copy of the program is required, but once loaded, the program can not be moved.

For comparison, on base or base-based or segmented systems such as Burroughs B5000 (1961) and Multics (1964), the code is inherently position independent, since the address in a program is relative to the current segment rather than absolute.

The position-independent code was developed to eliminate these restrictions for non-segmented systems. A position-independent program can be loaded at any address in memory.

The discovery of dynamic address translation (function provided by the MMU) initially reduces the need for position-independent code because each process can have its own independent address space (address range). However, multiple simultaneous jobs using the same code create a waste of physical memory. If two jobs run a fully identical program, dynamic address translation provides a solution by allowing the system to map only two different 32K job addresses to the same byte of the original memory, which contains one copy of the program.

Different programs can share common code. For example, payroll programs and accounts receivable programs may contain identical subroutines. The shared module (shared library is a shared module form) is loaded once and mapped into two address spaces.

Maps Position-independent code



Technical details

The procedure call in a shared library is usually done through the stubation of a small procedure linkage table, which then calls the definitive function. This primarily allows shared libraries to inherit certain function calls from previously loaded libraries rather than using their own version.

Data references from position-independent codes are usually made indirectly, through Global Offset Tables (GOTs), which store addresses of all global variables accessed. There is one GOT per compilation unit or object module, and it lies in the fixed offset of the code (although this offset is unknown until the library is connected). When the link connects the module to create a shared library, it combines GOT and sets the last offset in the code. No need to set offset when loading shared libraries later.

Position independent functions that access global data start by specifying the absolute address of GOT with their current program counter value. It often takes the form of a fake function call to get a return value on the stack (x86) or in a special list (PowerPC, SPARC, MIPS, perhaps at least some other RISC processor, ESA/390), which can then be stored in a predefined standard register. Some processor architectures, such as the Motorola 68000, Motorola 6809, WDC 65C816, Knuth's MMIX, ARM, and x86-64 allow reference data with offsets from the program counter. It's specifically targeted at making the code position-independent to be smaller, less demanding and therefore more efficient.

Computer Architecture and Assembly Language - ppt download
src: slideplayer.com


Windows DLL

Dynamic-link libraries (DLLs) in Microsoft Windows use the E8 variant of the CALL instruction (Near, relative, relative calls to the next instruction). These instructions need not be fixed when DLLs are loaded.

Some global variables (eg array literal string, virtual function table) are expected to contain the address of the object in the resp. in the code section of the dynamic library; Therefore, addresses stored in global variables need to be updated to reflect the address where DLLs are loaded. The dynamic loader calculates the address referenced by the global variable and stores the value in that global variable; this triggers a copy-on-write of a memory page containing such global variables. Pages with code and pages with global variables that do not contain code or global data instructions will still be shared between processes. This operation must be performed on any OS that can load dynamic libraries in arbitrary addresses.

In Windows Vista and later versions of Windows, relocation of DLLs and executables is performed by kernel memory manager, which shares binaries relocated in multiple processes. Images are always moved from the base address of their choice, reaching the address space layout (ASLR) randomization.

Windows versions prior to Vista require that the DLL system to prelink on addresses remain non-conflicts at time of links to avoid runtime relocation of images. The runtime relocation in older versions of Windows is done by the DLL loader in the context of each process, and the relocation part generated from each image can no longer be shared between processes.

The DLL submission in Windows differs from the previous OS/2 procedure from which it originated. OS/2 presents a third alternative and attempts to load an independent DLL position into a special "shared arena" in memory, and map it as soon as it is loaded. All DLL users can use copies in the same memory.

MOSDEF Dave Aitel Immunity, Inc - ppt download
src: images.slideplayer.com


Execution independent-position

Position-independent executable (PIE) is a binary executable made entirely of position-independent code. While some systems only run PIC executables, there are other reasons why they are used. PIE binaries are used in some security-focused Linux distributions to allow PaX or Exec Shield to use address space layout randomization to prevent attackers from knowing where execution code exists during a security attack using an exploit that depends on knowing offsets of executable code in binaries, such as back-to-libc attacks.

MacOS and iOS Apple fully supports PIE executables in versions 10.7 and 4.3, respectively; warnings issued when non-PIE iOS executables are submitted for approval to the Apple App Store but there is no difficult requirement and non-PIE applications are not rejected.

OpenBSD has enabled PIE by default in most architectures since OpenBSD 5.3, released on May 1, 2013. Support for PIEs in statically linked binaries, such as executable files in /bin and /sbin directory, added towards the end of 2014. Starting with Fedora 23, Fedora managers decided to create packages with PIE enabled as default. Ubuntu 17.10 has enabled PIE by default in all architectures, released on October 19, 2017. The new Gentoo profile now supports PIE by default.

Android-enabled support for PIEs in Jelly Bean and remove non-PIE link support in Lollipop.

CS 3214 Introduction to Computer Systems - ppt download
src: slideplayer.com


See also

  • Dynamic links
  • The code segment
  • COM file (though not the actual PIE)

Part 6: Special Topics Chapter 19: Shellcode Analysis Chapter 20 ...
src: images.slideplayer.com


References


SYSTEM A / ONE POSITION seacart26.com trimaran mast raise system ...
src: s-media-cache-ak0.pinimg.com


External links

  • Introduction Putting the Independent Code
  • The internal position of the Independent Code
  • Programming in Assembly with PIC

Source of the article : Wikipedia

Comments
0 Comments