From db35c87a85aa651b8ea3ed19689c53cefc28e313 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 18 Nov 2013 14:29:35 -0800 Subject: [PATCH] libdwfl: Fix and test aux_sym address_sync with relocated ELF The aux_sym address_sync already worked with a full prelink, which has .gnu.prelink_undo, but it failed on plain relocations with prelink -r. Now it uses the difference in ehdr.e_entry as a first offset guess, and the tests confirm this seems to work fine. Signed-off-by: Josh Stone --- libdwfl/ChangeLog | 5 ++++ libdwfl/dwfl_module_getdwarf.c | 45 +++++++++++++++++++++++---------- tests/ChangeLog | 7 +++++ tests/Makefile.am | 1 + tests/run-dwflsyms.sh | 10 ++++++++ tests/testfilebazdbg_plr.bz2 | Bin 0 -> 2241 bytes tests/testfilebazmin_plr.bz2 | Bin 0 -> 3337 bytes 7 files changed, 54 insertions(+), 14 deletions(-) create mode 100755 tests/testfilebazdbg_plr.bz2 create mode 100755 tests/testfilebazmin_plr.bz2 diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 990138051..ca328ded7 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2013-11-18 Josh Stone + + * dwfl_module_getdwarf.c (find_aux_address_sync): New function. + (find_aux_sym): Use it. + 2013-11-14 Jan Kratochvil Code cleanup: Remove const in prototype diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c index 7a65ec3bb..dd76f2579 100644 --- a/libdwfl/dwfl_module_getdwarf.c +++ b/libdwfl/dwfl_module_getdwarf.c @@ -816,6 +816,33 @@ find_dynsym (Dwfl_Module *mod) } } + +#if USE_LZMA +/* Try to find the offset between the main file and .gnu_debugdata. */ +static bool +find_aux_address_sync (Dwfl_Module *mod) +{ + /* Don't trust the phdrs in the minisymtab elf file to be setup correctly. + The address_sync is equal to the main file it is embedded in at first. */ + mod->aux_sym.address_sync = mod->main.address_sync; + + /* Adjust address_sync for the difference in entry addresses, attempting to + account for ELF relocation changes after aux was split. */ + GElf_Ehdr ehdr_main, ehdr_aux; + if (unlikely (gelf_getehdr (mod->main.elf, &ehdr_main) == NULL) + || unlikely (gelf_getehdr (mod->aux_sym.elf, &ehdr_aux) == NULL)) + return false; + mod->aux_sym.address_sync += ehdr_aux.e_entry - ehdr_main.e_entry; + + /* The shdrs are setup OK to make find_prelink_address_sync () do the right + thing, which is possibly more reliable, but it needs .gnu.prelink_undo. */ + if (mod->aux_sym.address_sync != 0) + return find_prelink_address_sync (mod, &mod->aux_sym) == DWFL_E_NOERROR; + + return true; +} +#endif + /* Try to find the auxiliary symbol table embedded in the main elf file section .gnu_debugdata. Only matters if the symbol information comes from the main file dynsym. No harm done if not found. */ @@ -879,21 +906,11 @@ find_aux_sym (Dwfl_Module *mod __attribute__ ((unused)), mod->aux_sym.elf->flags |= ELF_F_MALLOCED; if (open_elf (mod, &mod->aux_sym) != DWFL_E_NOERROR) return; - /* Don't trust the phdrs in the minisymtab elf file to be - setup correctly. The address_sync is equal to the main - file it is embedded in at first. The shdrs are setup - OK to make find_prelink_address_sync () do the right - thing if necessary though. */ - mod->aux_sym.address_sync = mod->main.address_sync; - if (mod->aux_sym.address_sync != 0) + if (! find_aux_address_sync (mod)) { - error = find_prelink_address_sync (mod, &mod->aux_sym); - if (error != DWFL_E_NOERROR) - { - elf_end (mod->aux_sym.elf); - mod->aux_sym.elf = NULL; - return; - } + elf_end (mod->aux_sym.elf); + mod->aux_sym.elf = NULL; + return; } /* So far, so good. Get minisymtab table data and cache it. */ diff --git a/tests/ChangeLog b/tests/ChangeLog index 9461287a7..9a8ac6132 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +2013-11-18 Josh Stone + + * testfilebazdbg_plr.bz2: New testfile. + * testfilebazmin_plr.bz2: Likewise. + * Makefile.am (EXTRA_DIST): Add the above files. + * run-dwflsyms.sh: Add prelink -r tests. + 2013-11-15 Mark Wielaard * testfilebazmdb.bz2: Regenerated. diff --git a/tests/Makefile.am b/tests/Makefile.am index e9cf950c1..4f8e9e49c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -190,6 +190,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfilebazmin.bz2 testfilebazdbg.debug.bz2 testfilebazmdb.bz2 \ testfilebaztab.bz2 testfilebasmin.bz2 \ testfilebazdbg_pl.bz2 testfilebazmin_pl.bz2 \ + testfilebazdbg_plr.bz2 testfilebazmin_plr.bz2 \ run-dwflsyms.sh \ run-unstrip-n.sh testcore-rtlib.bz2 testcore-rtlib-ppc.bz2 \ run-low_high_pc.sh testfile_low_high_pc.bz2 \ diff --git a/tests/run-dwflsyms.sh b/tests/run-dwflsyms.sh index a425277cf..2adec5a35 100755 --- a/tests/run-dwflsyms.sh +++ b/tests/run-dwflsyms.sh @@ -19,14 +19,18 @@ # Tests dwfl_module_{addrsym,getsym,relocate_address} # See run-readelf-s.sh for how to generate test binaries. +# In addition, *_pl files were created from their base file +# with prelink -N, and *_plr with prelink -r 0x4200000000. testfiles testfilebaztab testfiles testfilebazdbg testfilebazdbg.debug testfiles testfilebazdbg_pl +testfiles testfilebazdbg_plr testfiles testfilebazdyn testfiles testfilebazmdb testfiles testfilebazmin testfiles testfilebazmin_pl +testfiles testfilebazmin_plr testfiles testfilebasmin tempfiles testfile.dynsym.in testfile.symtab.in testfile.minsym.in dwflsyms.out @@ -328,6 +332,9 @@ cat testfile.symtab.in \ cat testfile.symtab_pl.in \ | testrun_compare ${abs_builddir}/dwflsyms -e testfilebazdbg_pl +sed s/0x3000/0x4200/g testfile.symtab_pl.in \ + | testrun_compare ${abs_builddir}/dwflsyms -e testfilebazdbg_plr + cat testfile.dynsym.in \ | testrun_compare ${abs_builddir}/dwflsyms -e testfilebazdyn @@ -340,6 +347,9 @@ cat testfile.minsym.in \ cat testfile.minsym_pl.in \ | testrun_compare ${abs_builddir}/dwflsyms -e testfilebazmin_pl +sed s/0x3000/0x4200/g testfile.minsym_pl.in \ + | testrun_compare ${abs_builddir}/dwflsyms -e testfilebazmin_plr + testrun_compare ${abs_builddir}/dwflsyms -e testfilebasmin <<\EOF 0: NOTYPE LOCAL (0) 0 1: FUNC LOCAL foo (18) 0x400168, rel: 0x400168 diff --git a/tests/testfilebazdbg_plr.bz2 b/tests/testfilebazdbg_plr.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..1bc43dd22ae2de4bf41a915ea2d900beec559a7b GIT binary patch literal 2241 zc-jHM2tM~hT4*^jL0KkKS-Tly%>V~)fB*mg{{H^||8M{I{@4Hi|MvfH)mKFFhYNrI z_k7-de{bLi7ge&pmcfy!I^8Qe6xMCwsiFc#B=pE>lT#4%LneWmOpOmoqfAUALrf=; z2dL4bO$JRg13>gcAT%@p02&$@G-Nb1(U59oGA60|0F9wf1fC%tkk9}$9-wFd01TQm z8UO%j00Te(008v>00w{tga8@_nluALO&T%)$)L~x(WXGi0077|X`llj8Vwp54Kf&+ z2AVVhp`bKq00gFpK>#VV0va^XPgMOTr=)(V>S^jdPe}5Ho}s6ddQGSrG->KTR5CQk zdWN2+hJ(}qX`pCmX!QZ6)C~XtJwXAWXa;~94Ky+UX`zB>G&CAw27t&7F#rLO00E!_ z2*4l!$Ql3u01`2ggCs|t6dEe4ZA`wl{_cdc%k~rGmb_QT z>~dL57VE`u{vT-hmu_q7%v}wWO*nwT%qn6!HrojehK-Y5XS9?mmZ~yKDsuucb8U%P ziuf|FPkJ5Pd=%W$b@BEqFIHKtv6qRTUPqHwqeBIjl+oPqtB#p*?n;jk>LkPgV>1rl z98yX_Ai)RF-6){Yn710>iovs*#Ew{`0S4+J{ns`*mIqsv@$_E(phYxx;uJh+V0gDD zCdX7}(797HF*{cqh~(9A_V|^IFw&=g<8H8Esb6%MRb5czA|g8E8;OchJDsMin|nc- z>fkumUHlsrPb;^(Ow1i*rE${z5sWk~xz{;$)RM?r_or^*8Z5XH=R|oPiiOJ<+eQms zu8IOQ(ucmAMIIGRbmTmZ#r;V1(;n1+ikzw3nE0TL^X2heIa$sjfyq`{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AovL#NQZs^8Dqxb}*vlShFl8v~ literal 0 Hc-jL100001 diff --git a/tests/testfilebazmin_plr.bz2 b/tests/testfilebazmin_plr.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..e4fcf85d21856066043e11dc1a18e75487d7416b GIT binary patch literal 3337 zc-no{X*?5v{|E5Rv5?i=NA7b(Ofw`UhR7VvEpjtgCFiJ?D`&)L=E#+sAyF1#t{mmq zh?HZIh#buw|NgJn|H1#k@AZ2>_&of6KF_{-4nA72YxZ(zd%y%90$|g5bn<_GpZrIU zPUhHehbu6}$=V8i@pSHcx-%&p%#pguJ7%tjS#gD-hs{yyIu+&kE&s{`lzbB})>U1j zIDnUN8Qss2$4?ia4N-V(&P9}ILE6pm5{9{)FVR0!|3jHkX-cfgc3yyJgLuog)k@w%B~SORqj4L3(qyN9LC6`JHE#z*1fMip4pSt_Jk z*sEwohey}L-Leo^M%2*-T`L@yLkR=m0A^hxd8qj zX#h}Fn4O2cV%(HiU|6|tN^~)`V2Bz18*BU%QR0iB0YK_!EdT%z4(@}n7^hA@DHSUO z=$OX%!r=e_7`TG@38MaM!~y<0pwxAlanr=Ah{Vzp02qQ8_b-(~n!e7Zk9%%^WIwli9#FP=@iI|cxL}FrT=CIc-7pJ)? znt6A-!{q5p4Av+w>N*!z@D2HWadPAOSc$x!xVBd@emeGW$*86V--tYuBr+GlH%!(R z`kZFlDq{8Lj#Q1t>QBBQ-7|Sd(he z+Q7tvL$})=4$iyJZ%M27{@kxOpL(?v(49Sb*j2s${%SdGC+N}x(K?ojwg>PcKf`M> zgZiZ=oubaXr7^$jp*7oDcF@o?eXqh;h4RG^`*V?4rv!hqT$>8suBxM65USAM=0!`Z zt4%Xo1|OCwRD9E$y$Z>+(Fx(_Z0hkY^w3+llFQLKaa48wms4N+!}CucYw_oehs^ve z%q@=ilt^pzgCT8w8Tqdj>vwaKSN7R`pi?M?NmHDOc&35EKM(WNq?%GXzg=)f?eDar~Fs-WwbrM zgA&1??3IS|)5`vF9G}f_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