[AVR][clang] Pass '-fno-use-init-array' to cc1 as default

On AVR, '.ctors' is used, not '.init_array'. Make this the default
unless specifically overridden by driver argument.

This matches gcc, and it matches the behavior in (e.g.) the NetBSD
driver (for certain OS variants).

Reviewed by: MaskRay

Differential Revision: https://reviews.llvm.org/D107610
This commit is contained in:
Matt Jacobson 2021-08-06 10:12:00 +08:00 committed by Ben Shi
parent 66b1e629d8
commit dae7adda94
3 changed files with 17 additions and 2 deletions

View File

@ -370,6 +370,16 @@ void AVRToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
addSystemInclude(DriverArgs, CC1Args, AVRInc);
}
void AVRToolChain::addClangTargetOptions(
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
Action::OffloadKind DeviceOffloadKind) const {
// By default, use `.ctors` (not `.init_array`), as required by libgcc, which
// runs constructors/destructors on AVR.
if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
options::OPT_fno_use_init_array, false))
CC1Args.push_back("-fno-use-init-array");
}
Tool *AVRToolChain::buildLinker() const {
return new tools::AVR::Linker(getTriple(), *this, LinkStdlib);
}

View File

@ -11,8 +11,8 @@
#include "Gnu.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
namespace clang {
namespace driver {
@ -26,6 +26,11 @@ public:
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
void
addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
Action::OffloadKind DeviceOffloadKind) const override;
protected:
Tool *buildLinker() const override;

View File

@ -1,7 +1,7 @@
// A basic clang -cc1 command-line.
// RUN: %clang %s -### -no-canonical-prefixes -target avr 2>&1 | FileCheck -check-prefix=CC1 %s
// CC1: clang{{.*}} "-cc1" "-triple" "avr"
// CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array"
// RUN: %clang %s -### -no-canonical-prefixes -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 | FileCheck -check-prefix CC1A %s
// CC1A: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" {{".*avr/include"}}