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.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'os/linux/elf.rb', line 249 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 |