Module: OS::Linux::Elf Private
- Defined in:
- os/linux/elf.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Helper functions for working with ELF objects.
Class Method Summary collapse
Class Method Details
.expand_elf_dst(str, ref, repl) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'os/linux/elf.rb', line 273 def self.(str, ref, repl) # ELF gABI rules for DSTs: # - Longest possible sequence using the rules (greedy). # - Must start with a $ (enforced by caller). # - Must follow $ with one underscore or ASCII [A-Za-z] (caller # follows these rules for REF) or '{' (start curly quoted name). # - Must follow first two characters with zero or more [A-Za-z0-9_] # (enforced by caller) or '}' (end curly quoted name). # (from https://github.com/bminor/glibc/blob/41903cb6f460d62ba6dd2f4883116e2a624ee6f8/elf/dl-load.c#L182-L228) # In addition to capturing a token, also attempt to capture opening/closing braces and check that they are not # mismatched before expanding. str.gsub(/\$({?)([a-zA-Z_][a-zA-Z0-9_]*)(}?)/) do |orig_str| has_opening_brace = ::Regexp.last_match(1).present? matched_text = ::Regexp.last_match(2) has_closing_brace = ::Regexp.last_match(3).present? if (matched_text == ref) && (has_opening_brace == has_closing_brace) repl else orig_str end end end |