RFA: GOLD: Allow INPUT linker script commands to input libraries

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

RFA: GOLD: Allow INPUT linker script commands to input libraries

Nick Clifton
Hi Ian,

  Currently GOLD's implementation of the INPUT linker script command
  does not support inputting libraries via the "-l<name>" syntax.  This
  is a problem as some current Linux libraries make use of this
  feature.  Eg the 64-bit version of the wide-character ncurses library
  looks like this:

    % cat /usr/lib64/libncursesw.so
    INPUT(libncursesw.so.5 -ltinfo)

  The attached patch is my poor attempt at adding support for this
  feature.  It works for the small test case I have been using locally,
  but I would certainly some guidance as to whether it is acceptable for
  inclusion into the gold sources.

  (Incidentally I wanted to put the check for the 'l' character in the
  "-l<name>" sequence into the yyscript.y file, but I could not get this
  to work.  I think that my bison-fu must be weak).

Cheers
  Nick

gold/ChangeLog
2010-06-08  Nick Clifton  <[hidden email]>

        * yyscript.y (input_list_element): Allow strings prefixed with
        the '-' character.  Treat these as libraries.
        * script.cc (script_add_library): New function.  Adds a library
        specified by "-l<name>" found in an input script.
        * script-c.h: Add prototype for script_add_library.


Index: gold/script-c.h
===================================================================
RCS file: /cvs/src/src/gold/script-c.h,v
retrieving revision 1.17
diff -c -3 -p -r1.17 script-c.h
*** gold/script-c.h 9 Apr 2010 17:32:58 -0000 1.17
--- gold/script-c.h 8 Jun 2010 11:46:22 -0000
*************** script_add_extern(void* closure, const c
*** 236,241 ****
--- 236,246 ----
  extern void
  script_add_file(void* closure, const char*, size_t);
 
+ /* Called by the bison parser to add a library to the link.  */
+
+ extern void
+ script_add_library(void* closure, const char*, size_t);
+
  /* Called by the bison parser to start and stop a group.  */
 
  extern void
Index: gold/script.cc
===================================================================
RCS file: /cvs/src/src/gold/script.cc,v
retrieving revision 1.72
diff -c -3 -p -r1.72 script.cc
*** gold/script.cc 18 May 2010 18:08:03 -0000 1.72
--- gold/script.cc 8 Jun 2010 11:46:22 -0000
*************** script_add_file(void* closurev, const ch
*** 2593,2598 ****
--- 2593,2616 ----
    closure->inputs()->add_file(file);
  }
 
+ // Called by the bison parser to add a library to the link.
+
+ extern "C" void
+ script_add_library(void* closurev, const char* name, size_t length)
+ {
+   Parser_closure* closure = static_cast<Parser_closure*>(closurev);
+   std::string name_string(name, length);
+
+   if (name_string[0] != 'l')
+     gold_error (_("library name must be prefixed with -l"));
+    
+   Input_file_argument file(name_string.c_str() + 1,
+   Input_file_argument::INPUT_FILE_TYPE_LIBRARY,
+   "", false,
+   closure->position_dependent_options());
+   closure->inputs()->add_file(file);
+ }
+
  // Called by the bison parser to start a group.  If we are already in
  // a group, that means that this script was invoked within a
  // --start-group --end-group sequence on the command line, or that
Index: gold/yyscript.y
===================================================================
RCS file: /cvs/src/src/gold/yyscript.y,v
retrieving revision 1.23
diff -c -3 -p -r1.23 yyscript.y
*** gold/yyscript.y 9 Apr 2010 17:32:58 -0000 1.23
--- gold/yyscript.y 8 Jun 2010 11:46:22 -0000
*************** input_list:
*** 320,325 ****
--- 320,327 ----
  input_list_element:
   string
     { script_add_file(closure, $1.value, $1.length); }
+ | '-' STRING
+    { script_add_library(closure, $2.value, $2.length); }
  | AS_NEEDED
     { script_start_as_needed(closure); }
   '(' input_list ')'
Reply | Threaded
Open this post in threaded view
|

Re: RFA: GOLD: Allow INPUT linker script commands to input libraries

Ian Lance Taylor
Nick Clifton <[hidden email]> writes:

> gold/ChangeLog
> 2010-06-08  Nick Clifton  <[hidden email]>
>
> * yyscript.y (input_list_element): Allow strings prefixed with
> the '-' character.  Treat these as libraries.
> * script.cc (script_add_library): New function.  Adds a library
> specified by "-l<name>" found in an input script.
> * script-c.h: Add prototype for script_add_library.


This looks good, except:

> +   if (name_string[0] != 'l')
> +     gold_error (_("library name must be prefixed with -l"));

No space before left parenthesis (confusing, I know).

Thanks.

Ian
Reply | Threaded
Open this post in threaded view
|

Re: RFA: GOLD: Allow INPUT linker script commands to input libraries

Nick Clifton
Hi Ian,

>> * yyscript.y (input_list_element): Allow strings prefixed with
>> the '-' character.  Treat these as libraries.
>> * script.cc (script_add_library): New function.  Adds a library
>> specified by "-l<name>" found in an input script.
>> * script-c.h: Add prototype for script_add_library.
>
>
> This looks good, except:
>
>> +   if (name_string[0] != 'l')
>> +     gold_error (_("library name must be prefixed with -l"));
>
> No space before left parenthesis (confusing, I know).

Oops - sorry, I missed that one.  Patch checked in with that correction
made.

Cheers
   Nick