From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11278 invoked by alias); 11 Oct 2013 21:26:07 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 11267 invoked by uid 89); 11 Oct 2013 21:26:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f182.google.com Received: from mail-pd0-f182.google.com (HELO mail-pd0-f182.google.com) (209.85.192.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 11 Oct 2013 21:26:06 +0000 Received: by mail-pd0-f182.google.com with SMTP id r10so4822118pdi.13 for ; Fri, 11 Oct 2013 14:26:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ba18oYoV4gUBQ3LlziFPCEeMZJfm2uVVhwTGD8xdB1E=; b=Lk1kZx7QjxGnLp4WMt37UUp6b+dLJwnxsle2Q2yE687LBe/9qsMqcpZIBqjq7+PWWS BsVBFhYKOIiT0/bH5oCaEobWgqGEMEgYc5SJIYhRAqamYljk6stm+iRGIZm050x2/mgc 0rkN1GVqqKFsvUhemTWJUqDF2a+kURaGOb9gTZusx9poZbeGORK3y1EDyvOozO5STdvL 4yWrB1El+kwVWbg7E9KFUixGBYU5sZ64/xEFD2O/iBgEqOKjHIDlC5dZix2/+QNPfS4k tay/t7mBb6an+Nj7/SRw6BwLWzT6GU8aaMI2lUet3iRtbDtLrMUwkkk4hcH87xKi1d7Q 4kAw== X-Gm-Message-State: ALoCoQl8VJrwjUvXepRaQDXi4HSW9vR+pVcWEq0IiHmu4NLHSpADz47AJfzyuf+0zjnPAIOx3Y41NGKHosZYEn6OoaKJ7D+BZgXH9dkZsrH5+ibtFuQ5wHHoZPcInCVndlo1PUiVUt6Iv6dsMxjM5aJGtvRNJHopm1NiL0wMVuiUFEMVT+2weZFyFTNo9tI9s9yu0v/kYZ4vIbXVXuLD5NZLkq4zd8v+AA== MIME-Version: 1.0 X-Received: by 10.69.0.103 with SMTP id ax7mr4147832pbd.188.1381526764186; Fri, 11 Oct 2013 14:26:04 -0700 (PDT) Received: by 10.68.8.101 with HTTP; Fri, 11 Oct 2013 14:26:04 -0700 (PDT) In-Reply-To: References: Date: Fri, 11 Oct 2013 21:26:00 -0000 Message-ID: Subject: Re: [PATCH] gold: remove false const from Target::do_adjust_elf_header From: Cary Coutant To: Roland McGrath Cc: "binutils@sourceware.org" Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00183.txt.bz2 There are a lot of places where we call parameters->target() and really do want a const Target&. If we're going to make it non-const, it really should be Target* instead of Target& (as a general rule, we don't like to return const references). The call to parameters->target().adjust_elf_header() in output.cc is so clearly wrong that I don't understand how this compiles with GCC (for ARM, that is). Just by leaving the "const" off of the override in Target_arm, we can completely subvert the const-ness of the reference returned by parameters->target()? I think a better approach would be to remove the "const" from the Target* passed to the Output_file_header ctor and stored in a private data member, then modify the call to adjust_elf_header() to be "this->target_->adjust_elf_header()". There's no reason to call parameters->target() here when we already have a pointer to the target readily available. -cary On Fri, Oct 11, 2013 at 11:46 AM, Roland McGrath wrote: > The claim of constness is false for Target_arm (because it calls > set_processor_specific_flags), so it should not be claimed for the > general case. > > OK for trunk and 2.24? > > > Thanks, > Roland > > > gold/ > * target.h (Target::adjust_elf_header, Target::adjust_elf_header): > Remove const from declaration. > * target.cc (Sized_target::do_adjust_elf_header): Update definition. > * sparc.cc (Target_sparc::do_adjust_elf_header): Likewise. > * parameters.h (Parameters::target): Make return value non-const. > > --- a/gold/parameters.h > +++ b/gold/parameters.h > @@ -99,7 +99,7 @@ class Parameters > { return this->target_ != NULL; } > > // The target of the output file we are generating. > - const Target& > + Target& > target() const > { > gold_assert(this->target_valid()); > --- a/gold/sparc.cc > +++ b/gold/sparc.cc > @@ -217,7 +217,7 @@ class Target_sparc : public Sized_target > const elfcpp::Ehdr& ehdr); > > void > - do_adjust_elf_header(unsigned char* view, int len) const; > + do_adjust_elf_header(unsigned char* view, int len); > > private: > > @@ -4341,7 +4341,7 @@ template > void > Target_sparc::do_adjust_elf_header( > unsigned char* view, > - int len) const > + int len) > { > elfcpp::Ehdr_write oehdr(view); > > --- a/gold/target.cc > +++ b/gold/target.cc > @@ -1,6 +1,6 @@ > // target.cc -- target support for gold. > > -// Copyright 2009, 2010, 2011 Free Software Foundation, Inc. > +// Copyright 2009, 2010, 2011, 2013 Free Software Foundation, Inc. > // Written by Doug Kwan . > > // This file is part of gold. > @@ -219,7 +219,7 @@ Target::do_plt_fde_location(const Output_data* > plt, unsigned char*, > template > void > Sized_target::do_adjust_elf_header(unsigned char* view, > - int len) const > + int len) > { > elfcpp::ELFOSABI osabi = this->osabi(); > if (osabi != elfcpp::ELFOSABI_NONE) > --- a/gold/target.h > +++ b/gold/target.h > @@ -1,6 +1,6 @@ > // target.h -- target support for gold -*- C++ -*- > > -// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 > +// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 > // Free Software Foundation, Inc. > // Written by Ian Lance Taylor . > > @@ -238,7 +238,7 @@ class Target > // Adjust the output file header before it is written out. VIEW > // points to the header in external form. LEN is the length. > void > - adjust_elf_header(unsigned char* view, int len) const > + adjust_elf_header(unsigned char* view, int len) > { return this->do_adjust_elf_header(view, len); } > > // Return address and size to plug into eh_frame FDEs associated with a PLT. > @@ -548,7 +548,7 @@ class Target > // By default, we set the EI_OSABI field if requested (in > // Sized_target). > virtual void > - do_adjust_elf_header(unsigned char*, int) const = 0; > + do_adjust_elf_header(unsigned char*, int) = 0; > > // Return address and size to plug into eh_frame FDEs associated with a PLT. > virtual void > @@ -1018,7 +1018,7 @@ class Sized_target : public Target > > // Set the EI_OSABI field if requested. > virtual void > - do_adjust_elf_header(unsigned char*, int) const; > + do_adjust_elf_header(unsigned char*, int); > > // Handle target specific gc actions when adding a gc reference. > virtual void