• Peter Collingbourne's avatar
    Android: Determine search path by taking the address of a function instead of a variable. · eb412d96
    Peter Collingbourne authored
    The GetCrazyContext function calls the
    crazy_context_add_search_path_for_address function to add the directory
    where the crazy linker library was loaded from to the search path.
    This function works by reading /proc/self/maps to discover the path
    of the file from which the address passed as the second argument is
    mapped, which is expected to be the crazy linker library.
    
    However, there is no guarantee that the address of a static variable
    such as s_crazy_context will be mapped; the linker may allocate them
    into an unmapped region of the r/w segment.  This happens to be what
    lld does with this variable. Because the address was not mapped,
    we ended up failing to determine the search path, which led to a
    failure to load libchrome.so in pre-modern APKs.
    
    We can more reasonably rely on functions being memory mapped, so this
    change causes us to take the address of a function instead.
    
    Bug: 779185
    Change-Id: I83cd882567c48a2cca443b7f5781c50ebc1b9bb4
    Reviewed-on: https://chromium-review.googlesource.com/745201Reviewed-by: default avataragrieve <agrieve@chromium.org>
    Commit-Queue: Peter Collingbourne <pcc@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#512698}
    eb412d96
legacy_linker_jni.cc 15.7 KB