From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3376 invoked by alias); 14 Aug 2012 03:30:36 -0000 Received: (qmail 3367 invoked by uid 22791); 14 Aug 2012 03:30:36 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-lb0-f169.google.com (HELO mail-lb0-f169.google.com) (209.85.217.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Aug 2012 03:30:21 +0000 Received: by lbon3 with SMTP id n3so5591lbo.0 for ; Mon, 13 Aug 2012 20:30:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.42.34 with SMTP id k2mr7149663lbl.11.1344915019977; Mon, 13 Aug 2012 20:30:19 -0700 (PDT) Received: by 10.112.126.141 with HTTP; Mon, 13 Aug 2012 20:30:19 -0700 (PDT) In-Reply-To: References: Date: Tue, 14 Aug 2012 03:39:00 -0000 Message-ID: Subject: Re: [GOLD] How can I add a undefined symbol in target implementation, not by "-u SYM" from command line ? From: Jiong WANG To: Ian Lance Taylor Cc: binutils@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 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 X-SW-Source: 2012-08/txt/msg00246.txt.bz2 2012/8/13 Ian Lance Taylor : > On Mon, Aug 13, 2012 at 3:25 AM, Jiong WANG wrote: >> >> How can I predefine a undefined symbol in target implementation? >> >> actually, I am porting gold for tilegx, and our arch's tls >> implementation requires predefiniation of "_tls_get_addr" because the >> assembler generate relocation which use this symbol implicitly. >> >> I know there are interfaces, "define_in_output_data/segment" to >> predefined symbol with value, but there is no interface to predefine >> "undefined" symbol ? >> >> gold linker do support this by command line "-u SYMBOL", but it's >> a compile time decision not link time. >> >> currently, I managed to support this by the following ugly code: >> >> options::parse_set(NULL, "_tls_get_addr", >> (gold::options::String_set*)¶meters->options().undefined()); >> >> which is bad, so, could anyone give me some suggestion on this? > > > I assume that the symbol is defined somewhere. You probably want to > add a do_is_defined_by_abi method to your Target. See the examples in > existing targets. Hi Ian & all, thanks for your suggestion. I have explored do_is_defined_by_abi, and found it's mostly to avoid warning, but not for creating such a symbol do_is_defined_by_abi has one argument of the type "const Symbol*", so when it's invoked, that symbol should already existed. below is my ugly code to create a external symbol which is not from any object files, but pretend to be case elfcpp::R_TILEGX_TLS_GD_CALL: // FIXME: // ugly code to predefine _tls_get_addr // should be fixed later if (!target->tls_get_addr_sym_defined_) { Symbol* sym = NULL; options::parse_set(NULL, "__tls_get_addr", (gold::options::String_set*)¶meters->options().undefined()); symtab->add_undefined_symbols_from_command_line(layout); target->tls_get_addr_sym_defined_ = true; sym = symtab->lookup("__tls_get_addr"); sym->set_in_reg(); } target->make_plt_entry(symtab, layout, symtab->lookup("__tls_get_addr")); break; basically, I want to create a symbol which is neither against section or segment, just a normally external function symbol. above code works when use gcc driver to invoke gold, because libc.so are involved in. but it still failed, when use gold directly by: tile-ld -shared -o libtls.so tls.o tile-ld: internal error in get_symbol_index, at ../binutils/gold/output.cc:1031 I think there maybe some other graceful and standard way to solve this problem. please feel free to give any suggestion thanks very much ! --- Regards, WANG.Jiong > > Ian