WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH 7 of 7] xl: Use gcc hidden visibility attribute

FYI, here is a hacky script to locate self-PLT entries in x86_64
binaries. It depends on binutils and elfutils and clobbers a file called
'./syms' in order to avoid having to think about deadlocks in rw popen.

8<-----------------------------------
#!/usr/bin/python

import os,sys

def check_file(fn):
    f_plt = os.popen("eu-readelf --relocs %s| grep 'X86_64_JUMP_SLOT 0x' | awk 
'{print $5}'"%fn)
    plt = {}.fromkeys(map(lambda x:x.rstrip("\r\n"), f_plt.readlines()))
    del f_plt

    f_ref = os.popen("objdump -d %s | egrep '\<callq\>.*@plt' | awk '{print $1 
$9}'"%fn)

    tmp = map(lambda x:x.split(":"), f_ref.readlines())
    del f_ref

    refs = []
    for x in tmp:
        assert(len(x) == 2)
        (addr, sym) = x
        sym = sym.rstrip(">\r\n").lstrip("<")
        assert(len(sym) > 4 and sym[-4:] == '@plt')
        sym = sym[:-4]
        addr = int(addr, 16)
        refs.append((addr,sym))
    del tmp

    refs = filter(lambda x:plt.has_key(x[1]), refs)
    f_eu = os.popen("xargs eu-addr2line -e %s > syms"%fn, 'w')
    for (addr,sym) in refs:
        f_eu.write("0x%x\n"%addr)
        #print "0x%x %s"%(addr,sym)
    f_eu.close()

    f_eu = open("syms", 'r')
    os.unlink("syms")
    addrlines = map(lambda x:x.rstrip("\r\n"), f_eu.readlines())
    del f_eu

    assert(len(addrlines) == len(refs))

    for ((addr, sym), line) in zip(refs, addrlines):
        print "%s -> %s"%(line, sym)

    return True

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print "Usage: %s <ELF-lib>"%sys.argv[0]
        raise SystemExit, 1
    if check_file(sys.argv[1]):
        raise SystemExit
    raise SystemExit, 1



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel