This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Patch to "generalize" setting section start addresses via command line
- To: binutils at sourceware dot cygnus dot com
- Subject: Patch to "generalize" setting section start addresses via command line
- From: Thomas de Lellis <tdel at windriver dot com>
- Date: Fri, 19 May 2000 14:07:16 -0700
Patch to "generalize" setting of section start addresses
via the command line.
The GNU ld linker only allows -T with the
.text, .data, and .bss sections via the command line
options:
-Ttext org
-Tdata org
-Tbss org
The gnu linker is also quirky in that -T is used for both
section start addresses and using external linker command files.
If you use -T with ANY other name besides text/data/bss, it
assumes it's looking for an external linker command script.
We needed a simple way to set start adresses of other sections
from the command line, but, we also use -T for external linker
scripts so wanted to preserve all the present ld behavior. We
ended up adding a new command line option:
--section-start sectionname=org
sectionname can be any section instead of just .text/.data/.bss
and you must include all the characters (.) in your section
names... (the syntax is like that of -defsym)
--section-start .mysection=0x20000
:
:
-Ttext 0x1234 translates to --section-start .text=0x1234
=======================================================================
ld/ChangeLog
2000-05-15 Thomas de Lellis <tdel@windriver.com>
* ld.1: added documentation for new command line option
--section-start sectionname=sectionorg
This is a generic version of -Ttext etc. which accepts
any section name as a parameter instead of just
text/data/bss.
* ld.texinfo: more docs.
* ldgram.y: add code for processing of --section-start option
* ldlex.h: ditto.
* ldlex.l: ditto.
* ldlexsup: (parse_args): recognize new command line option.
=======================================================================
*** ld.1 Thu May 18 18:13:24 2000
--- ld.1.new Thu May 18 18:27:00 2000
*************** ld \- the GNU linker
*** 122,127 ****
--- 122,133 ----
.RB "[\|" "\-T\ "\c
.I commandfile\c
\&\|]
+ .br
+ .RB "[\|" "\-\-section\-start\ "\c
+ .I sectionname\c
+ \& = \c
+ .I sectionorg\c
+ \&\|]
.RB "[\|" "\-Ttext\ "\c
.I textorg\c
\&\|]
*************** The exceptions\(em\&which may meaningful
*** 253,260 ****
.B \-format\c
\&), \c
.B \-defsym\c
! \&,
! \c
.B \-L\c
\&, \c
.B \-l\c
--- 259,267 ----
.B \-format\c
\&), \c
.B \-defsym\c
! \&, \c
! .B \-\-section\-start\c
! \&, \c
.B \-L\c
\&, \c
.B \-l\c
*************** relocations one output section will cont
*** 888,893 ****
--- 895,919 ----
Similar to
.B \-split\-by\-reloc
but creates a new output section for each input file.
+
+ .TP
+ .BI "--section-start " "sectionname" "\fR = \fP" expression
+ Locate a section in the output file at the absolute
+ address given by \c
+ .I expression\c
+ \&. You may use this option as many
+ times as necessary to locate multiple sections in the command line. A
+ limited form of arithmetic is supported for the \c
+ .I expression\c
+ \& in this
+ context: you may give a hexadecimal constant or the name of an existing
+ symbol, or use \c
+ .B +\c
+ \& and \c
+ .B \-\c
+ \& to add or subtract hexadecimal
+ constants or symbols. If you need more elaborate expressions, consider
+ using the linker command language from a script.
.TP
.BI "\-Tbss " "org"\c
=======================================================================
*** ld/ld.texinfo Fri May 19 11:02:15 2000
--- newld/ld.texinfo Fri May 19 11:16:15 2000
*************** full debugging information by over 30 pe
*** 1143,1148 ****
--- 1143,1162 ----
trouble). The @samp{--traditional-format} switch tells @code{ld} to not
combine duplicate entries.
+ @kindex --section-start @var{sectionname}=@var{exp}
+ @item --section-start @var{sectionname}=@var{expression}
+ Locate a section in the output file at the absolute
+ address given by @var{expression}. You may use this option as many
+ times as necessary to locate multiple sections in the command line. A
+ limited form of arithmetic is supported for the @var{expression} in this
+ context: you may give a hexadecimal constant or the name of an existing
+ symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
+ constants or symbols. If you need more elaborate expressions, consider
+ using the linker command language from a script (@pxref{Assignments,,
+ Assignment: Symbol Definitions}). @emph{Note:} there should be no white
+ space between @var{symbol}, the equals sign (``@key{=}''), and
+ @var{expression}.
+
@kindex -Tbss @var{org}
@kindex -Tdata @var{org}
@kindex -Ttext @var{org}
=======================================================================
*** ld/ldgram.y Fri May 19 11:02:16 2000
--- newld/ldgram.y Fri May 19 13:24:17 2000
*************** static int error_index;
*** 144,149 ****
--- 144,150 ----
%token GLOBAL LOCAL VERSIONK INPUT_VERSION_SCRIPT
%token KEEP
%token EXCLUDE_FILE
+ %token INPUT_SECTION_START
%type <versyms> vers_defns
%type <versnode> vers_tag
%type <deflist> verdep
*************** file:
*** 155,160 ****
--- 156,162 ----
| INPUT_MRI_SCRIPT mri_script_file
| INPUT_VERSION_SCRIPT version_script_file
| INPUT_DEFSYM defsym_expr
+ | INPUT_SECTION_START section_start_expr
;
*************** defsym_expr:
*** 167,172 ****
--- 169,182 ----
{
ldlex_popstate();
lang_add_assignment(exp_assop($3,$2,$4));
+ }
+
+ section_start_expr:
+ { ldlex_section_start(); }
+ NAME '=' exp
+ {
+ ldlex_popstate();
+ lang_section_start($2,$4);
}
/* SYNTAX WITHIN AN MRI SCRIPT FILE */
=======================================================================
*** ld/ldlex.h Fri May 19 11:02:19 2000
--- newld/ldlex.h Fri May 19 13:27:55 2000
*************** typedef enum input_enum {
*** 29,35 ****
input_script,
input_mri_script,
input_version_script,
! input_defsym
} input_type;
extern input_type parser_input;
--- 29,36 ----
input_script,
input_mri_script,
input_version_script,
! input_defsym,
! input_section_start
} input_type;
extern input_type parser_input;
*************** extern void ldlex_mri_script PARAMS ((vo
*** 46,51 ****
--- 47,53 ----
extern void ldlex_version_script PARAMS ((void));
extern void ldlex_version_file PARAMS ((void));
extern void ldlex_defsym PARAMS ((void));
+ extern void ldlex_section_start PARAMS ((void));
extern void ldlex_expression PARAMS ((void));
extern void ldlex_both PARAMS ((void));
extern void ldlex_command PARAMS ((void));
=======================================================================
*** ld/ldlex.l Fri May 19 11:02:19 2000
--- newld/ldlex.l Fri May 19 13:41:20 2000
*************** static void lex_warn_invalid PARAMS ((ch
*** 87,93 ****
EXPRESSION definitely in an expression
SCRIPT definitely in a script
BOTH either EXPRESSION or SCRIPT
! DEFSYMEXP in an argument to -defsym
MRI in an MRI script
VERS_START starting a Sun style mapfile
VERS_SCRIPT a Sun style mapfile
--- 87,93 ----
EXPRESSION definitely in an expression
SCRIPT definitely in a script
BOTH either EXPRESSION or SCRIPT
! DEFSYMEXP in an argument to -defsym or --start-section
MRI in an MRI script
VERS_START starting a Sun style mapfile
VERS_SCRIPT a Sun style mapfile
*************** V_IDENTIFIER [*?.$_a-zA-Z][*?.$_a-zA-Z0-
*** 138,143 ****
--- 138,144 ----
case input_mri_script: return INPUT_MRI_SCRIPT; break;
case input_version_script: return INPUT_VERSION_SCRIPT; break;
case input_defsym: return INPUT_DEFSYM; break;
+ case input_section_start: return INPUT_SECTION_START; break;
default: abort ();
}
}
*************** ldlex_version_file ()
*** 549,554 ****
--- 550,562 ----
void
ldlex_defsym ()
+ {
+ *(state_stack_p)++ = yy_start;
+ BEGIN (DEFSYMEXP);
+ }
+
+ void
+ ldlex_section_start ()
{
*(state_stack_p)++ = yy_start;
BEGIN (DEFSYMEXP);
=======================================================================
*** ld/lexsup.c Fri May 19 11:02:20 2000
--- newld/lexsup.c Fri May 19 13:54:38 2000
*************** int parsing_defsym = 0;
*** 123,128 ****
--- 123,129 ----
#define OPTION_NO_UNDEFINED (OPTION_MPC860C0 + 1)
#define OPTION_INIT (OPTION_NO_UNDEFINED + 1)
#define OPTION_FINI (OPTION_INIT + 1)
+ #define OPTION_SECTION_START (OPTION_FINI + 1)
/* The long options. This structure is used for both the option
parsing and the help text. */
*************** static const struct ld_option ld_options
*** 336,341 ****
--- 337,344 ----
'\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
{ {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
'\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
+ { {"section-start", required_argument, NULL, OPTION_SECTION_START},
+ '\0', N_("SYMBOL=EXPRESSION"), N_("Set address of named section"), TWO_DASHES },
{ {"Tbss", required_argument, NULL, OPTION_TBSS},
'\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
{ {"Tdata", required_argument, NULL, OPTION_TDATA},
*************** parse_args (argc, argv)
*** 585,590 ****
--- 588,600 ----
parsing_defsym = 1;
yyparse ();
parsing_defsym = 0;
+ lex_string = NULL;
+ break;
+ case OPTION_SECTION_START:
+ lex_string = optarg;
+ lex_redirect (optarg);
+ parser_input = input_section_start;
+ yyparse ();
lex_string = NULL;
break;
case OPTION_DEMANGLE:
=======================================================================