1 // inremental.cc -- incremental linking test/deubg tool
3 // Copyright 2009 Free Software Foundation, Inc.
4 // Written by Rafael Avila de Espindola <rafael.espindola@gmail.com>
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
24 // This file is a (still incomplete) test/debug tool that should display
25 // all information available in the incremental linking sections in a
26 // format that is easy to read.
27 // Once the format is a bit more stable, this should probably be moved to
28 // readelf. Because of that, the use of gold's data structures and functions
29 // is just a short term convenience and not a design decision.
36 #include "incremental.h"
46 main(int argc
, char** argv
)
50 fprintf(stderr
, "Usage: %s <file>\n", argv
[0]);
53 const char* filename
= argv
[1];
55 Output_file
* file
= new Output_file(filename
);
57 bool t
= file
->open_for_modification();
60 fprintf(stderr
, "%s: open_for_modification(%s): %s\n", argv
[0], filename
,
65 Incremental_binary
* inc
= open_incremental_binary(file
);
69 fprintf(stderr
, "%s: open_incremental_binary(%s): %s\n", argv
[0],
70 filename
, strerror(errno
));
74 unsigned int strtab_shndx
;
75 Incremental_binary::Location location
;
77 t
= inc
->find_incremental_inputs_section(&location
, &strtab_shndx
);
80 fprintf(stderr
, "%s: %s: no .gnu_incremental_inputs section\n", argv
[0],
85 Incremental_binary::View
inputs_view(inc
->view(location
));
86 const unsigned char *p
= inputs_view
.data();
88 const Incremental_inputs_header_data
* incremental_header
=
89 reinterpret_cast<const Incremental_inputs_header_data
*> (p
);
91 const Incremental_inputs_entry_data
* incremental_inputs
=
92 reinterpret_cast<const Incremental_inputs_entry_data
*>
93 (p
+ sizeof(Incremental_inputs_header_data
));
95 if (incremental_header
->version
!= 1)
97 fprintf(stderr
, "%s: %s: unknown incremestal version %d\n", argv
[0],
98 filename
, incremental_header
->version
);
102 elfcpp::Elf_file
<64, false, Incremental_binary
> elf_file(inc
);
104 if (elf_file
.section_type(strtab_shndx
) != elfcpp::SHT_STRTAB
)
107 "%s: %s: invalid string table section %u (type %d != %d)\n",
108 argv
[0], filename
, strtab_shndx
,
109 elf_file
.section_type(strtab_shndx
), elfcpp::SHT_STRTAB
);
113 Incremental_binary::Location
114 strtab_location(elf_file
.section_contents(strtab_shndx
));
116 Incremental_binary::View
strtab_view(inc
->view(strtab_location
));
117 p
= strtab_view
.data();
119 elfcpp::Elf_strtab
strtab(strtab_view
.data(), strtab_location
.data_size
);
120 const char* command_line
;
121 t
= strtab
.get_c_string(incremental_header
->command_line_offset
,
127 "%s: %s: failed to get link command line: %zu out of range\n",
129 static_cast<size_t>(incremental_header
->command_line_offset
));
133 printf("Link command line: %s\n", command_line
);
135 printf("Input files:\n");
136 for (unsigned i
= 0; i
< incremental_header
->input_file_count
; ++i
)
138 const Incremental_inputs_entry_data
* input
=
139 &incremental_inputs
[i
];
142 t
= strtab
.get_c_string(input
->filename_offset
, &objname
);
145 fprintf(stderr
,"%s: %s: failed to get file name for object %u:"
146 " %zu out of range\n", argv
[0], filename
, i
,
147 static_cast<size_t>(input
->filename_offset
));
150 printf(" %s\n", objname
);
151 printf(" Timestamp sec = %ld\n", input
->timestamp_sec
);
152 printf(" Timestamp nsec = %d\n", input
->timestamp_nsec
);
154 // TODO: print the data at input->data_offset once we have it.
155 switch (input
->input_type
)
157 case INCREMENTAL_INPUT_OBJECT
:
160 case INCREMENTAL_INPUT_ARCHIVE
:
163 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
164 printf("Shared library\n");
166 case INCREMENTAL_INPUT_SCRIPT
:
167 printf("Linker script\n");
169 case INCREMENTAL_INPUT_INVALID
:
171 fprintf(stderr
, "%s: invalid file type for object %u: %d\n",
172 argv
[0], i
, input
->input_type
);