// plugin.cc -- plugin manager for gold -*- C++ -*-
-// Copyright (C) 2008-2018 Free Software Foundation, Inc.
+// Copyright (C) 2008-2022 Free Software Foundation, Inc.
// Written by Cary Coutant <ccoutant@google.com>.
// This file is part of gold.
// Create a temporary directory where we can stash the log and
// copies of replacement files.
char dir_template[] = "gold-recording-XXXXXX";
+#ifdef HAVE_MKDTEMP
if (mkdtemp(dir_template) == NULL)
return false;
+#else
+ if (mktemp(dir_template) == NULL)
+ return false;
+#if defined (_WIN32) && !defined (__CYGWIN32__)
+ if (mkdir(dir_template) != 0)
+ return false;
+#else
+ if (mkdir(dir_template, 0700) != 0)
+ return false;
+#endif
+#endif
size_t len = strlen(dir_template) + 1;
char* tempdir = new char[len];
- strncpy(tempdir, dir_template, len);
+ memcpy(tempdir, dir_template, len);
// Create the log file.
std::string logname(tempdir);
{
static char buf[4096];
+#ifdef HAVE_LINK
if (::link(inname, outname) == 0)
return true;
+#endif
int in = ::open(inname, O_RDONLY);
if (in < 0)
{
- gold_warning(_("%s: can't open (%s)\n"), inname, strerror(errno));
+ gold_warning(_("%s: can't open (%s)"), inname, strerror(errno));
return false;
}
int out = ::open(outname, O_CREAT | O_TRUNC | O_WRONLY, 0600);
if (out < 0)
{
- gold_warning(_("%s: can't create (%s)\n"), outname, strerror(errno));
+ gold_warning(_("%s: can't create (%s)"), outname, strerror(errno));
::close(in);
return false;
}
ssize_t len;
while ((len = ::read(in, buf, sizeof(buf))) > 0)
- static_cast<void>(::write(out, buf, len));
+ {
+ if (::write(out, buf, len) != len)
+ {
+ gold_warning(_("%s: write error while making copy of file (%s)"),
+ inname, strerror(errno));
+ break;
+ }
+ }
::close(in);
::close(out);
return true;
this->objects_.push_back(elf_object);
this->in_claim_file_handler_ = true;
- for (this->current_ = this->plugins_.begin();
- this->current_ != this->plugins_.end();
- ++this->current_)
+ for (Plugin_list::iterator p = this->plugins_.begin();
+ p != this->plugins_.end();
+ ++p)
{
// If we aren't yet in replacement phase, allow plugins to claim input
// files, otherwise notify the plugin of the new input file, if needed.
if (!this->in_replacement_phase_)
- {
- if ((*this->current_)->claim_file(&this->plugin_input_file_))
- {
- this->any_claimed_ = true;
+ {
+ if ((*p)->claim_file(&this->plugin_input_file_))
+ {
+ this->any_claimed_ = true;
this->in_claim_file_handler_ = false;
if (this->recorder_ != NULL)
: elf_object->name());
this->recorder_->claimed_file(objname,
offset, filesize,
- (*this->current_)->filename());
+ (*p)->filename());
}
if (this->objects_.size() > handle
}
else
{
- (*this->current_)->new_input(&this->plugin_input_file_);
+ (*p)->new_input(&this->plugin_input_file_);
}
}
layout->script_options()->set_defsym_uses_in_real_elf(symtab);
layout->script_options()->find_defsym_defs(this->defsym_defines_set_);
- for (this->current_ = this->plugins_.begin();
- this->current_ != this->plugins_.end();
- ++this->current_)
- (*this->current_)->all_symbols_read();
+ for (Plugin_list::iterator p = this->plugins_.begin();
+ p != this->plugins_.end();
+ ++p)
+ (*p)->all_symbols_read();
if (this->any_added_)
{
close_all_descriptors();
}
- for (this->current_ = this->plugins_.begin();
- this->current_ != this->plugins_.end();
- ++this->current_)
- (*this->current_)->cleanup();
+ for (Plugin_list::iterator p = this->plugins_.begin();
+ p != this->plugins_.end();
+ ++p)
+ (*p)->cleanup();
}
// Make a new Pluginobj object. This is called when the plugin calls
{
const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
unsigned char symbuf[sym_size];
- elfcpp::Sym<size, big_endian> sym(symbuf);
elfcpp::Sym_write<size, big_endian> osym(symbuf);
Plugin_recorder* recorder = parameters->options().plugins()->recorder();
{
case LDPK_DEF:
case LDPK_WEAKDEF:
- shndx = elfcpp::SHN_ABS;
+ // We use an arbitrary section number for a defined symbol.
+ shndx = 1;
break;
case LDPK_COMMON:
shndx = elfcpp::SHN_COMMON;
osym.put_st_other(vis, 0);
osym.put_st_shndx(shndx);
+ elfcpp::Sym<size, big_endian> sym(symbuf);
this->symbols_[i] =
symtab->add_from_pluginobj<size, big_endian>(this, name, ver, &sym);
}