-
Notifications
You must be signed in to change notification settings - Fork 35
/
abi-dumper.pl
executable file
·6850 lines (5929 loc) · 176 KB
/
abi-dumper.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
###########################################################################
# ABI Dumper 1.3
# Dump ABI of an ELF object containing DWARF debug info
#
# Copyright (C) 2013-2021 Andrey Ponomarenko's ABI Laboratory
#
# Written by Andrey Ponomarenko
#
# PLATFORMS
# =========
# Linux
#
# REQUIREMENTS
# ============
# Perl 5 (5.8 or newer)
# Elfutils (eu-readelf)
# GNU Binutils (objdump)
# Vtable-Dumper (1.1 or newer)
# Universal Ctags
# GCC C++
#
# COMPATIBILITY
# =============
# ABI Compliance Checker >= 2.2
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
###########################################################################
use Getopt::Long;
Getopt::Long::Configure ("posix_default", "no_ignore_case", "permute");
use File::Path qw(mkpath rmtree);
use File::Temp qw(tempdir);
use Cwd qw(abs_path cwd realpath);
use Storable qw(dclone);
use Data::Dumper;
my $TOOL_VERSION = "1.3";
my $ABI_DUMP_VERSION = "3.5";
my $ORIG_DIR = cwd();
my $TMP_DIR = tempdir(CLEANUP=>1);
my $VTABLE_DUMPER = "vtable-dumper";
my $VTABLE_DUMPER_VERSION = "1.0";
my $LOCALE = "LANG=C.UTF-8";
my $EU_READELF = "eu-readelf";
my $EU_READELF_L = $LOCALE." ".$EU_READELF;
my $OBJDUMP = "objdump";
my $CTAGS = "ctags";
my $EXUBERANT_CTAGS = 0;
my $GPP = "g++";
my ($Help, $ShowVersion, $DumpVersion, $OutputDump, $SortDump, $StdOut,
$TargetVersion, $ExtraInfo, $FullDump, $AllTypes, $AllSymbols, $BinOnly,
$SkipCxx, $Loud, $AddrToName, $DumpStatic, $Compare, $AltDebugInfoOpt,
$AddDirs, $VTDumperPath, $SymbolsListPath, $PublicHeadersPath,
$IgnoreTagsPath, @CtagsDef, $KernelExport, $UseTU, $ReimplementStd,
$IncludePreamble, $IncludePaths, $CacheHeaders, $MixedHeaders, $Debug,
$SearchDirDebuginfo, $KeepRegsAndOffsets, $Quiet, $IncludeDefines,
$AllUnits, $LambdaSupport, $LdLibraryPath);
my $CmdName = getFilename($0);
my %ERROR_CODE = (
"Success"=>0,
"Error"=>2,
# System command is not found
"Not_Found"=>3,
# Cannot access input files
"Access_Error"=>4,
# Cannot find a module
"Module_Error"=>9,
# No debug-info
"No_DWARF"=>10,
# Invalid debug-info
"Invalid_DWARF"=>11,
# No exported symbols
"No_Exported"=>12
);
my $ShortUsage = "ABI Dumper $TOOL_VERSION
Dump ABI of an ELF object containing DWARF debug info
Copyright (C) 2021 Andrey Ponomarenko's ABI Laboratory
License: GNU LGPL 2.1
Usage: $CmdName [options] [object]
Example:
$CmdName libTest.so -o ABI.dump
$CmdName Module.ko.debug -o ABI.dump
More info: $CmdName --help\n";
if($#ARGV==-1)
{
printMsg("INFO", $ShortUsage);
exit(0);
}
GetOptions("h|help!" => \$Help,
"v|version!" => \$ShowVersion,
"dumpversion!" => \$DumpVersion,
# general options
"o|output|dump-path=s" => \$OutputDump,
"sort!" => \$SortDump,
"stdout!" => \$StdOut,
"loud!" => \$Loud,
"vnum|lver|lv=s" => \$TargetVersion,
"extra-info=s" => \$ExtraInfo,
"bin-only!" => \$BinOnly,
"all-types!" => \$AllTypes,
"all-symbols!" => \$AllSymbols,
"symbols-list=s" => \$SymbolsListPath,
"skip-cxx!" => \$SkipCxx,
"all!" => \$FullDump,
"dump-static!" => \$DumpStatic,
"compare!" => \$Compare,
"alt=s" => \$AltDebugInfoOpt,
"dir!" => \$AddDirs,
"vt-dumper=s" => \$VTDumperPath,
"public-headers=s" => \$PublicHeadersPath,
"ignore-tags=s" => \$IgnoreTagsPath,
"ctags-def=s" => \@CtagsDef,
"mixed-headers!" => \$MixedHeaders,
"kernel-export!" => \$KernelExport,
"search-debuginfo=s" => \$SearchDirDebuginfo,
"keep-registers-and-offsets!" => \$KeepRegsAndOffsets,
"all-units!" => \$AllUnits,
"quiet!" => \$Quiet,
"debug!" => \$Debug,
# extra options
"use-tu-dump!" => \$UseTU,
"include-preamble=s" => \$IncludePreamble,
"include-paths=s" => \$IncludePaths,
"include-defines=s" => \$IncludeDefines,
"cache-headers=s" => \$CacheHeaders,
"lambda!" => \$LambdaSupport,
"ld-library-path=s" => \$LdLibraryPath,
# internal options
"addr2name!" => \$AddrToName,
# obsolete
"reimplement-std!" => \$ReimplementStd
) or errMsg();
sub errMsg()
{
printMsg("INFO", "\n".$ShortUsage);
exit($ERROR_CODE{"Error"});
}
my $HelpMessage="
NAME:
ABI Dumper ($CmdName)
Dump ABI of an ELF object containing DWARF debug info
DESCRIPTION:
ABI Dumper is a tool for dumping ABI information of an ELF object
containing DWARF debug info.
The tool is intended to be used with ABI Compliance Checker tool for
tracking ABI changes of a C/C++ library or kernel module.
This tool is free software: you can redistribute it and/or modify it
under the terms of the GNU LGPL 2.1.
USAGE:
$CmdName [options] [object]
EXAMPLES:
$CmdName libTest.so -o ABI.dump
$CmdName Module.ko.debug -o ABI.dump
INFORMATION OPTIONS:
-h|-help
Print this help.
-v|-version
Print version information.
-dumpversion
Print the tool version ($TOOL_VERSION) and don't do anything else.
GENERAL OPTIONS:
-o|-output PATH
Path to the output ABI dump file.
Default: ./ABI.dump
-sort
Sort data in ABI dump.
-stdout
Print ABI dump to stdout.
-loud
Print all warnings.
-vnum NUM
Set version of the library to NUM.
-extra-info DIR
Dump extra analysis info to DIR.
-bin-only
Do not dump information about inline functions,
pure virtual functions and non-exported global data.
-all-types
Dump unused data types.
-all-symbols
Dump symbols not exported by the object.
-symbols-list PATH
Specify a file with a list of symbols that should be dumped.
-skip-cxx
Do not dump stdc++ and gnu c++ symbols.
-all
Equal to: -all-types -all-symbols.
-dump-static
Dump static (local) symbols.
-compare OLD.dump NEW.dump
Show added/removed symbols between two ABI dumps.
-alt PATH
Path to the alternate debug info (Fedora). It is
detected automatically from gnu_debugaltlink section
of the input object if not specified.
-dir
Show full paths of source files.
-vt-dumper PATH
Path to the vtable-dumper executable if it is installed
to non-default location (not in PATH).
-public-headers PATH
Path to directory with public header files or to file with
the list of header files. This option allows to filter out
private symbols from the ABI dump.
-ignore-tags PATH
Path to ignore.tags file to help ctags tool to read
symbols in header files.
-ctags-def DEF
Add -D DEF option to the ctags call. This option may be
specified multiple times.
-reimplement-std
Do nothing.
-mixed-headers
This option should be specified if you are using
-public-headers option and the names of public headers
intersect with the internal headers.
-kernel-export
Dump symbols exported by the Linux kernel and modules, i.e.
symbols declared in the ksymtab section of the object and
system calls.
-search-debuginfo DIR
Search for debug-info files referenced from gnu_debuglink
section of the object in DIR.
-keep-registers-and-offsets
Dump used registers and stack offsets even if incompatible
build options detected.
-all-units
Extract ABI info after reading all compilation units from
the debug info. This may require a lot of extra RAM memory.
By default all compilation units are processed separately.
-quiet
Do not warn about incompatible build options.
-debug
Enable debug messages.
EXTRA OPTIONS:
-use-tu-dump
Use g++ -fdump-translation-unit instead of ctags to
list symbols in headers. This may be useful if all
functions are declared via macros in headers and
ctags can't recognize them.
-include-preamble PATHS
Specify header files (separated by semicolon) that
should be included before others to compile without
errors.
-include-paths DIRS
Specify include directories (separated by semicolon)
that should be passed to the compiler by -I option
in order to compile headers without errors. If this
option is not set then the tool will try to generate
include paths automatically.
-cache-headers DIR
Cache headers analysis results to reuse later.
-lambda
Enable support for lambda and checking of lexical
blocks. Define it if your C++ library API functions
use lambda expressions.
-ld-library-path PATHS
Specify paths to add to LD_LIBRARY_PATH variable before
executing vtable-dumper (separated by colon).
By default lexical blocks are not analyzed to
improve performance.
";
sub helpMsg() {
printMsg("INFO", $HelpMessage);
}
my %Cache;
# Input
my %DWARF_Info;
my @IDs;
# Alternate
my @IDs_I;
my $AltDebugInfo = undef;
my $TooBig = 0;
my $Compressed = undef;
my $Partial = undef;
# Dump
my %TypeUnit;
my %Post_Change;
# Output
my %TypeInfo;
my %SymbolInfo;
# Other
my $TargetName = undef;
my %NestedNameSpaces;
my %HeadersInfo;
my %SourcesInfo;
my %SymVer;
my %LexicalId;
# Reader (per compile unit)
my %TypeMember;
my %ArrayCount;
my %FuncParam;
my %TmplParam;
my %Inheritance;
my %NameSpace;
my %SpecElem;
my %OrigElem;
my %ClassMethods;
# Reader
my %TypeSpec;
my %ClassChild;
my %SourceFile;
my %SourceFile_Alt;
my %DebugLoc;
my %TName_Tid;
my %TName_Tids;
my %RegName;
my $STDCXX_TARGET = 0;
my $GLOBAL_ID = 0;
my %ANON_TYPE_WARN = ();
my %Mangled_ID;
my %Checked_Spec;
my %SelectedSymbols;
# Cleaning
my %MergedTypes;
my %LocalType;
my %UsedType;
my %DeletedAnon;
my %CheckedType;
my %DuplBaseType;
# Language
my %TypeType = (
"class_type"=>"Class",
"structure_type"=>"Struct",
"union_type"=>"Union",
"enumeration_type"=>"Enum",
"subroutine_type"=>"Func",
"array_type"=>"Array",
"base_type"=>"Intrinsic",
"atomic_type"=>"Intrinsic",
"unspecified_type"=>"Unspecified",
"const_type"=>"Const",
"pointer_type"=>"Pointer",
"reference_type"=>"Ref",
"rvalue_reference_type"=>"RvalueRef",
"volatile_type"=>"Volatile",
"restrict_type"=>"Restrict",
"typedef"=>"Typedef",
"ptr_to_member_type"=>"FieldPtr",
"string_type"=>"String"
);
my %Qual = (
"Pointer"=>"*",
"Ref"=>"&",
"RvalueRef"=>"&&",
"Volatile"=>"volatile",
"Restrict"=>"restrict",
"Const"=>"const"
);
my %ConstSuffix = (
"unsigned int" => "u",
"unsigned long" => "ul",
"unsigned long long" => "ull",
"long" => "l",
"long long" => "ll"
);
my $HEADER_EXT = "h|hh|hp|hxx|hpp|h\\+\\+|tcc|txx|x|inl|inc|ads|isph";
my $SRC_EXT = "c|cc|cp|cpp|cxx|c\\+\\+";
# ELF
my %Library_Symbol;
my %Library_UndefSymbol;
my %Library_Needed;
my %SymbolTable;
my %Symbol_Bind;
# Kernel
my %KSymTab;
# VTables
my %VirtualTable;
# Env
my $SYS_ARCH;
my $SYS_WORD;
my $SYS_GCCV;
my $SYS_CLANGV = undef;
my $SYS_COMP;
my $LIB_LANG;
my $OBJ_LANG;
# Errors
my $InvalidDebugLoc;
my $IncompatibleOpt = undef;
my $FKeepInLine = undef;
# Public Headers
my %SymbolToHeader;
my %TypeToHeader;
my %PublicHeader;
my $PublicSymbols_Detected;
my $PublicHeadersIsDir = 1;
# Filter
my %SymbolsList;
# Dump
my $COMPRESS = "tar.gz";
sub printMsg($$)
{
my ($Type, $Msg) = @_;
if($Type!~/\AINFO/) {
$Msg = $Type.": ".$Msg;
}
if($Type!~/_C\Z/) {
$Msg .= "\n";
}
if($Type eq "ERROR"
or $Type eq "WARNING") {
print STDERR $Msg;
}
else {
print $Msg;
}
}
sub exitStatus($$)
{
my ($Code, $Msg) = @_;
printMsg("ERROR", $Msg);
exit($ERROR_CODE{$Code});
}
sub cmpVersions($$)
{ # compare two versions in dotted-numeric format
my ($V1, $V2) = @_;
return 0 if($V1 eq $V2);
return undef if($V1!~/\A\d+[\.\d+]*\Z/);
return undef if($V2!~/\A\d+[\.\d+]*\Z/);
my @V1Parts = split(/\./, $V1);
my @V2Parts = split(/\./, $V2);
for (my $i = 0; $i <= $#V1Parts && $i <= $#V2Parts; $i++) {
return -1 if(int($V1Parts[$i]) < int($V2Parts[$i]));
return 1 if(int($V1Parts[$i]) > int($V2Parts[$i]));
}
return -1 if($#V1Parts < $#V2Parts);
return 1 if($#V1Parts > $#V2Parts);
return 0;
}
sub writeFile($$)
{
my ($Path, $Content) = @_;
if(my $Dir = getDirname($Path)) {
mkpath($Dir);
}
open(FILE, ">", $Path) || die ("can't open file \'$Path\': $!\n");
print FILE $Content;
close(FILE);
}
sub readFile($)
{
my $Path = $_[0];
open(FILE, $Path);
local $/ = undef;
my $Content = <FILE>;
close(FILE);
return $Content;
}
sub getFilename($)
{ # much faster than basename() from File::Basename module
if($_[0] and $_[0]=~/([^\/\\]+)[\/\\]*\Z/) {
return $1;
}
return "";
}
sub getDirname($)
{ # much faster than dirname() from File::Basename module
if($_[0] and $_[0]=~/\A(.*?)[\/\\]+[^\/\\]*[\/\\]*\Z/) {
return $1;
}
return "";
}
sub sepPath($) {
return (getDirname($_[0]), getFilename($_[0]));
}
sub checkCmd($)
{
my $Cmd = $_[0];
if(defined $Cache{"checkCmd"}{$Cmd}) {
return $Cache{"checkCmd"}{$Cmd};
}
if(-x $Cmd)
{ # relative or absolute path
return ($Cache{"checkCmd"}{$Cmd} = 1);
}
foreach my $Path (sort {length($a)<=>length($b)} split(/:/, $ENV{"PATH"}))
{
if(-x $Path."/".$Cmd) {
return ($Cache{"checkCmd"}{$Cmd} = 1);
}
}
return ($Cache{"checkCmd"}{$Cmd} = 0);
}
my %ELF_BIND = map {$_=>1} (
"WEAK",
"GLOBAL",
"LOCAL"
);
my %ELF_TYPE = map {$_=>1} (
"FUNC",
"IFUNC",
"GNU_IFUNC",
"TLS",
"OBJECT",
"COMMON"
);
my %ELF_VIS = map {$_=>1} (
"DEFAULT",
"PROTECTED"
);
sub readline_ELF($)
{ # read the line of 'eu-readelf' output corresponding to the symbol
my @Info = split(/\s+/, $_[0]);
# Num: Value Size Type Bind Vis Ndx Name
# 3629: 000b09c0 32 FUNC GLOBAL DEFAULT 13 _ZNSt12__basic_fileIcED1Ev@@GLIBCXX_3.4
# 135: 00000000 0 FUNC GLOBAL DEFAULT UNDEF av_image_fill_pointers@LIBAVUTIL_52 (3)
shift(@Info) if($Info[0] eq ""); # spaces
shift(@Info); # num
if($#Info==7)
{ # UNDEF SYMBOL (N)
if($Info[7]=~/\(\d+\)/) {
pop(@Info);
}
}
if($#Info!=6)
{ # other lines
return ();
}
return () if(not defined $ELF_TYPE{$Info[2]} and $Info[5] ne "UNDEF");
return () if(not defined $ELF_BIND{$Info[3]});
return () if(not defined $ELF_VIS{$Info[4]});
if($Info[5] eq "ABS" and $Info[0]=~/\A0+\Z/)
{ # 1272: 00000000 0 OBJECT GLOBAL DEFAULT ABS CXXABI_1.3
return ();
}
if(index($Info[2], "0x") == 0)
{ # size == 0x3d158
$Info[2] = hex($Info[2]);
}
return @Info;
}
sub readSymbols($)
{
my $Lib_Path = $_[0];
my $Lib_Name = getFilename($Lib_Path);
my $Dynamic = ($Lib_Name=~/\.so(\.|\Z)/);
my $Dbg = ($Lib_Name=~/\.debug\Z/);
if(not checkCmd($EU_READELF)) {
exitStatus("Not_Found", "can't find \"eu-readelf\" from Elfutils");
}
my %SectionInfo;
my %KSect;
my $Cmd = $EU_READELF_L." -S \"$Lib_Path\" 2>\"$TMP_DIR/error\"";
foreach (split(/\n/, `$Cmd`))
{
if(/\[\s*(\d+)\]\s+([\w\.]+)/)
{
my ($Num, $Name) = ($1, $2);
$SectionInfo{$Num} = $Name;
if(defined $KernelExport)
{
if($Name=~/\A(__ksymtab|__ksymtab_gpl)\Z/) {
$KSect{$1} = 1;
}
}
}
}
if(defined $KernelExport)
{
if(not keys(%KSect))
{
printMsg("ERROR", "can't find __ksymtab or __ksymtab_gpl sections in the object");
exit(1);
}
foreach my $Name (sort keys(%KSect))
{
$Cmd = $OBJDUMP." --section=$Name -d \"$Lib_Path\" 2>\"$TMP_DIR/error\"";
foreach my $Line (split(/\n/, qx/$Cmd/))
{
if($Line=~/<__ksymtab_(.+?)>/)
{
$KSymTab{$1} = 1;
}
}
}
}
if($Dynamic)
{ # dynamic library specifics
$Cmd = $EU_READELF_L." -d \"$Lib_Path\" 2>\"$TMP_DIR/error\"";
foreach (split(/\n/, `$Cmd`))
{
if(/NEEDED.+\[([^\[\]]+)\]/)
{ # dependencies:
# 0x00000001 (NEEDED) Shared library: [libc.so.6]
$Library_Needed{$1} = 1;
}
}
}
my $ExtraPath = undef;
if($ExtraInfo)
{
mkpath($ExtraInfo);
$ExtraPath = $ExtraInfo."/elf-info";
}
$Cmd = $EU_READELF_L." -s \"$Lib_Path\" 2>\"$TMP_DIR/error\"";
if($ExtraPath)
{ # debug mode
# write to file
system($Cmd." >\"$ExtraPath\"");
open(LIB, $ExtraPath);
}
else
{ # write to pipe
open(LIB, $Cmd." |");
}
my (%Symbol_Value, %Value_Symbol) = ();
my $symtab = undef; # indicates that we are processing 'symtab' section of 'readelf' output
while(<LIB>)
{
if($Dynamic and not $Dbg)
{ # dynamic library specifics
if(defined $symtab)
{
if(index($_, "'.dynsym'")!=-1)
{ # dynamic table
$symtab = undef;
}
if(not $AllSymbols)
{ # do nothing with symtab
# next;
}
}
elsif(index($_, "'.symtab'")!=-1)
{ # symbol table
$symtab = 1;
}
}
if(my ($Value, $Size, $Type, $Bind, $Vis, $Ndx, $Symbol) = readline_ELF($_))
{ # read ELF entry
$Symbol_Bind{$Symbol} = $Bind;
if(index($Symbol, '@')!=-1)
{
if($Symbol=~/\A(.+?)\@/) {
$Symbol_Bind{$1} = $Bind;
}
}
if(not $symtab)
{ # dynsym
if(skipSymbol($Symbol)) {
next;
}
if($Ndx eq "UNDEF")
{ # ignore interfaces that are imported from somewhere else
$Library_UndefSymbol{$TargetName}{$Symbol} = 0;
next;
}
if(defined $KernelExport)
{
if($Bind ne "LOCAL")
{
if(index($Symbol, "sys_")==0
or index($Symbol, "SyS_")==0) {
$KSymTab{$Symbol} = 1;
}
}
if(not defined $KSymTab{$Symbol}) {
next;
}
}
if($Bind ne "LOCAL") {
$Library_Symbol{$TargetName}{$Symbol} = ($Type eq "OBJECT")?-$Size:1;
}
if(not defined $OBJ_LANG)
{
if(index($Symbol, "_Z")==0)
{
$OBJ_LANG = "C++";
}
}
}
if($Ndx ne "UNDEF" and $Value!~/\A0+\Z/)
{
$Symbol_Value{$Symbol} = $Value;
$Value_Symbol{$Value}{$Symbol} = 1;
}
if(not $symtab)
{
foreach ($SectionInfo{$Ndx}, "")
{
my $Val = $Value;
$SymbolTable{$_}{$Val}{$Symbol} = 1;
if($Val=~s/\A[0]+//)
{
if($Val eq "") {
$Val = "0";
}
$SymbolTable{$_}{$Val}{$Symbol} = 1;
}
}
}
}
}
close(LIB);
if(not defined $Library_Symbol{$TargetName}) {
return;
}
my %Found = ();
foreach my $Symbol (sort keys(%Symbol_Value))
{
next if(index($Symbol, '@')==-1);
if(my $Value = $Symbol_Value{$Symbol})
{
foreach my $Symbol_SameValue (sort keys(%{$Value_Symbol{$Value}}))
{
if($Symbol_SameValue ne $Symbol
and index($Symbol_SameValue, '@')==-1)
{
$SymVer{$Symbol_SameValue} = $Symbol;
$Found{$Symbol} = 1;
if(index($Symbol, '@@')==-1) {
last;
}
}
}
}
}
# default
foreach my $Symbol (sort keys(%Symbol_Value))
{
next if(defined $Found{$Symbol});
next if(index($Symbol, '@@')==-1);
if($Symbol=~/\A([^\@]*)\@\@/
and not $SymVer{$1})
{
$SymVer{$1} = $Symbol;
$Found{$Symbol} = 1;
}
}
# non-default
foreach my $Symbol (sort keys(%Symbol_Value))
{
next if(defined $Found{$Symbol});
next if(index($Symbol, '@')==-1);
if($Symbol=~/\A([^\@]*)\@([^\@]*)/
and not $SymVer{$1})
{
$SymVer{$1} = $Symbol;
$Found{$Symbol} = 1;
}
}
if(not defined $OBJ_LANG)
{
$OBJ_LANG = "C";
}
}
sub readAltInfo($)
{
my $Path = $_[0];
my $Name = getFilename($Path);
if(not checkCmd($EU_READELF)) {
exitStatus("Not_Found", "can't find \"$EU_READELF\" command");
}
printMsg("INFO", "Reading alternate debug-info");
my $ExtraPath = undef;
# lines info
if($ExtraInfo)
{
$ExtraPath = $ExtraInfo."/alt";
mkpath($ExtraPath);
$ExtraPath .= "/debug_line";
}
if($ExtraPath)
{
system($EU_READELF_L." -N --debug-dump=line \"$Path\" 2>\"$TMP_DIR/error\" >\"$ExtraPath\"");
open(SRC, $ExtraPath);
}
else {
open(SRC, $EU_READELF_L." -N --debug-dump=line \"$Path\" 2>\"$TMP_DIR/error\" |");
}
my $DirTable_Def = undef;
my %DirTable = ();
while(<SRC>)
{
if(defined $AddDirs)
{
if(/Directory table/i)
{
$DirTable_Def = 1;
next;
}
elsif(/File name table/i)
{
$DirTable_Def = undef;
next;
}
if(defined $DirTable_Def)
{
if(/\A\s*(.+?)\Z/) {
$DirTable{keys(%DirTable)+1} = $1;
}
elsif(/\A\s*(\d+)\s+(.+?)\s+\(\d+\)\Z/)
{ # F34
$DirTable{$1} = $2;
}
}
}
my ($Num, $Dir, $File) = ();
if(/(\d+)\s+(\d+)\s+\d+\s+\d+\s+([^ ]+)/) {
($Num, $Dir, $File) = ($1, $2, $3)
}
elsif(/(\d+)\s+([^ ]+)\s+\(\d+\)\,\s+(\d+)/)
{ # F34
($Num, $File, $Dir) = ($1, $2, $3);
}
if($File)
{
chomp($File);
if(defined $AddDirs)
{
if(my $DName = $DirTable{$Dir})
{
$File = $DName."/".$File;
}
}
$SourceFile_Alt{0}{$Num} = $File;
}
}
close(SRC);
# debug info
if($ExtraInfo)
{
$ExtraPath = $ExtraInfo."/alt";
mkpath($ExtraPath);
$ExtraPath .= "/debug_info";
}
my $INFO_fh;
if($ExtraPath)
{
system($EU_READELF_L." -N --debug-dump=info \"$Path\" 2>\"$TMP_DIR/error\" >\"$ExtraPath\"");
open($INFO_fh, $ExtraPath);
}
else {
open($INFO_fh, $EU_READELF_L." -N --debug-dump=info \"$Path\" 2>\"$TMP_DIR/error\" |");
}