Position Independent Code Global Variable Access Optimization

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Position independent binaries require extra memory loads to access global variables, leading to performance deterioration due to their position-dependent nature, which exposes them to security risks.

Innovation Solution

The method involves compiling position independent code to create executable binaries without generating memory load instructions for global variable addresses, by determining if the global variable is defined in the executable binary and creating a definition if not, or using a list of defined global variables to optimize memory loads, or employing static relocations to directly load global variables from their addresses.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If position independent code is compiled with conventional techniques, then security risks are avoided through address space layout randomization, but extra memory load operations are required when accessing global variables causing performance deterioration

Engineering Contradiction:
ImprovesecurityVSAvoidperformance
Core Design Contradiction:
ReliabilityVSProductivity

Solution Approach 1:

The patent applies preliminary action by pre-defining global variables within the executable binary during the compilation process. The compiler identifies global variables and creates definitions for them in the binary before execution, so that during runtime, these variables can be accessed directly without requiring memory load operations from the global offset table. This advance preparation eliminates the performance penalty while maintaining position independence and security.

Inventive Principle:
Principle #10Preliminary action

2Productivity

If memory load instructions are eliminated for global variable addresses, then performance is improved, but the position independence property may be compromised

Engineering Contradiction:
ImproveperformanceVSAvoidposition independence
Core Design Contradiction:
ProductivityVSAdaptability or versatility

Solution Approach 1:

The patent applies local quality by creating definitions for global variables locally within the executable binary, rather than requiring all global variables to be accessed through the global offset table. This localized definition approach allows the binary to maintain position independence while optimizing access to specific global variables. The compiler selectively defines global variables within the binary based on their usage patterns, creating a hybrid approach that combines position independence with performance optimization.

Inventive Principle:
Principle #3Local quality

Data Source

PatentUS9213531B2Methods to eliminate extra memory loads while accessing global variables in position independent code
Publication Date: 2015.12.15 GOOGLE LLC
  • US9213531B2 patent drawing
  • US9213531B2 patent drawing
  • US9213531B2 patent drawing

AI summary

Methods for reducing memory loads for accessing global variables (globals) when creating executables for position independent (PI) code are disclosed. A first method includes compiling PI code, identifying globals, and determining whether globals are defined in the executable. If a global is not defined in the executable, a definition is created in the executable. A second method includes receiving a list of defined globals from instrumented PI code binary and comparing the list with globals in the PI code. Memory loads are created for globals that are unlisted. A third method includes compiling PI code with special relocations for globals and determining whether globals are defined in the executable. If the global is defined in the executable, the special relocation is replaced with a direct load of the global. If not, the special relocation is replaced with a two-instruction sequence that loads the global's address and then the global's value.