Skip to content

Commit b9127f3

Browse files
author
Daniel Kroening
committed
linker_script_merget now takes exactly one ELF + goto binary
1 parent cd967db commit b9127f3

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/goto-cc/gcc_mode.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,14 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
937937

938938
int result=run_gcc(compiler);
939939

940-
if(result==0)
940+
if(result==0 &&
941+
cmdline.isset('T') &&
942+
goto_binaries.size()==1 &&
943+
output_files.size()==1)
941944
{
942945
linker_script_merget ls_merge(
943-
compiler, output_files, goto_binaries, cmdline, gcc_message_handler);
946+
compiler, output_files.front(), goto_binaries.front(),
947+
cmdline, gcc_message_handler);
944948
result=ls_merge.add_linker_script_definitions();
945949
}
946950

src/goto-cc/linker_script_merge.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@ Author: Kareem Khazem <[email protected]>, 2017
2727

2828
int linker_script_merget::add_linker_script_definitions()
2929
{
30-
if(!cmdline.isset('T') || elf_binaries.size()!=1)
30+
if(!cmdline.isset('T'))
3131
return 0;
32-
const std::string &elf_file=*elf_binaries.begin();
33-
const std::string &goto_file=*goto_binaries.begin();
3432

3533
temporary_filet linker_def_outfile("goto-cc-linker-info", ".json");
3634
std::list<irep_idt> linker_defined_symbols;
3735
int fail=
3836
get_linker_script_data(
3937
linker_defined_symbols,
4038
compiler.symbol_table,
41-
elf_file,
39+
elf_binary,
4240
linker_def_outfile());
4341
// ignore linker script parsing failures until the code is tested more widely
4442
if(fail!=0)
@@ -62,8 +60,10 @@ int linker_script_merget::add_linker_script_definitions()
6260

6361
symbol_tablet original_st;
6462
goto_functionst original_gf;
65-
fail=read_goto_binary(goto_file, original_st, original_gf,
63+
64+
fail=read_goto_binary(goto_binary, original_st, original_gf,
6665
get_message_handler());
66+
6767
if(fail!=0)
6868
{
6969
error() << "Unable to read goto binary for linker script merging" << eom;
@@ -100,26 +100,29 @@ int linker_script_merget::add_linker_script_definitions()
100100

101101
fail=pointerize_linker_defined_symbols(original_gf, original_st,
102102
linker_values);
103+
103104
if(fail!=0)
104105
{
105106
error() << "Could not pointerize all linker-defined expressions" << eom;
106107
return fail;
107108
}
108109

109-
fail=compiler.write_object_file(goto_file, original_st, original_gf);
110+
fail=compiler.write_object_file(goto_binary, original_st, original_gf);
111+
110112
if(fail!=0)
111113
error() << "Could not write linkerscript-augmented binary" << eom;
114+
112115
return fail;
113116
}
114117

115118
linker_script_merget::linker_script_merget(
116119
compilet &compiler,
117-
const std::list<std::string> &elf_binaries,
118-
const std::list<std::string> &goto_binaries,
120+
const std::string &elf_binary,
121+
const std::string &goto_binary,
119122
const cmdlinet &cmdline,
120123
message_handlert &message_handler) :
121124
messaget(message_handler), compiler(compiler),
122-
elf_binaries(elf_binaries), goto_binaries(goto_binaries),
125+
elf_binary(elf_binary), goto_binary(goto_binary),
123126
cmdline(cmdline),
124127
replacement_predicates(
125128
{

src/goto-cc/linker_script_merge.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ class linker_script_merget:public messaget
8282
typedef std::map<irep_idt, std::pair<symbol_exprt, exprt>> linker_valuest;
8383

8484
linker_script_merget(
85-
compilet &,
86-
const std::list<std::string> &elf_binaries,
87-
const std::list<std::string> &goto_binaries,
88-
const cmdlinet &,
89-
message_handlert &);
85+
compilet &,
86+
const std::string &elf_binary,
87+
const std::string &goto_binary,
88+
const cmdlinet &,
89+
message_handlert &);
9090

9191
protected:
9292
compilet &compiler;
93-
const std::list<std::string> &elf_binaries;
94-
const std::list<std::string> &goto_binaries;
93+
const std::string &elf_binary;
94+
const std::string &goto_binary;
9595
const cmdlinet &cmdline;
9696

9797
/// \brief The "shapes" of expressions to be replaced by a pointer

0 commit comments

Comments
 (0)