Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions src/goto-cc/gcc_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,34 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
}
objcopy_cmd+="objcopy";

#ifdef __linux__
if(act_as_ld && cmdline.get_value('m')=="i386pep")
{
for(const auto &object_file : compiler.object_files)
{
debug() << "stripping goto-cc sections before building EFI binary" << eom;
// create a backup copy
std::string bin_name=object_file+goto_binary_tmp_suffix;

std::ifstream in(object_file, std::ios::binary);
std::ofstream out(bin_name, std::ios::binary);
out << in.rdbuf();

// remove any existing goto-cc section
std::vector<std::string> objcopy_argv;

objcopy_argv.push_back(objcopy_cmd);
objcopy_argv.push_back("--remove-section=goto-cc");
objcopy_argv.push_back(object_file);

int result=run(objcopy_argv[0], objcopy_argv, "", "");
if(result!=0)
debug() << "EFI binary preparation: removing goto-cc section failed"
<< eom;
}
}
#endif

int result=run_gcc(compiler);

if(result==0)
Expand All @@ -950,6 +978,21 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
result=ls_merge.add_linker_script_definitions();
}

#ifdef __linux__
if(act_as_ld && cmdline.get_value('m')=="i386pep")
{
debug() << "arch set with " << compiler.object_files.size() << eom;
for(const auto &object_file : compiler.object_files)
{
debug() << "EFI binary preparation: restoring object files" << eom;
std::string bin_name=object_file+goto_binary_tmp_suffix;
int mv_result=rename(bin_name.c_str(), object_file.c_str());
if(mv_result!=0)
debug() << "Rename failed: " << std::strerror(errno) << eom;
}
}
#endif

// merge output from gcc with goto-binaries
// using objcopy, or do cleanup if an earlier call failed
for(std::list<std::string>::const_iterator
Expand All @@ -970,7 +1013,9 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
objcopy_argv.push_back("--remove-section=goto-cc");
objcopy_argv.push_back(*it);

result=run(objcopy_argv[0], objcopy_argv, "", "");
int rs_result=run(objcopy_argv[0], objcopy_argv, "", "");
if(rs_result!=0 && (!act_as_ld || cmdline.get_value('m')!="i386pep"))
result=rs_result;
}

if(result==0)
Expand All @@ -983,7 +1028,15 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
objcopy_argv.push_back("goto-cc="+saved);
objcopy_argv.push_back(*it);

result=run(objcopy_argv[0], objcopy_argv, "", "");
int as_result=run(objcopy_argv[0], objcopy_argv, "", "");
if(as_result!=0)
{
if(act_as_ld && cmdline.get_value('m')=="i386pep")
warning() << "cannot merge EFI binaries: goto-cc section lost"
<< eom;
else
result=as_result;
}
}

int remove_result=remove(saved.c_str());
Expand Down
11 changes: 11 additions & 0 deletions src/linking/linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,17 @@ void linkingt::duplicate_code_symbol(
if(!found)
break;
}
// different non-pointer arguments with implementation - the
// implementation is always right, even though such code may
// be severely broken
else if(pointer_offset_bits(t1, ns)==pointer_offset_bits(t2, ns) &&
old_symbol.value.is_nil()!=new_symbol.value.is_nil())
{
if(warn_msg.empty())
warn_msg="non-pointer parameter types differ between "
"declaration and definition";
replace=new_symbol.value.is_not_nil();
}
else
break;

Expand Down