Patch to "generalize" setting section start addresses via command line - TAKE 2
Thomas de Lellis
tdel@windriver.com
Mon May 22 13:51:00 GMT 2000
Nick Clifton wrote:
> I think it should be relatively easy for you to change your patch so
> that the code in parse_args() actually parses the entirety of your new
> switch and then calls lang_section_start() directly. If you would
> like to do that and then resubmit the patch I will be happy to review
> it again.
Hi Nick,
thanks for the tips.
Here's a new and improved (and simpler) patch...
Tom
TAKE 2
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-22 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.
* ldlexsup: (parse_args): recognize new command line option.
=======================================================================
*** ../ld/ld.1 Fri May 19 11:02:12 2000
--- ld.1 Mon May 22 13:35:00 2000
*************** ld \- the GNU linker
*** 39,45 ****
.br
.RB "[\|" "\-defsym\ "\c
.I symbol\c
! \& = \c
.I expression\c
\&\|]
.RB "[\|" \-\-demangle "\|]"
--- 39,45 ----
.br
.RB "[\|" "\-defsym\ "\c
.I symbol\c
! \&=\c
.I expression\c
\&\|]
.RB "[\|" \-\-demangle "\|]"
*************** ld \- the GNU linker
*** 122,127 ****
--- 122,132 ----
.RB "[\|" "\-T\ "\c
.I commandfile\c
\&\|]
+ .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
--- 258,266 ----
.B \-format\c
\&), \c
.B \-defsym\c
! \&, \c
! .B \-\-section\-start\c
! \&, \c
.B \-L\c
\&, \c
.B \-l\c
*************** specified (\c
*** 454,460 ****
\& has the same effect.
.TP
! .BI "-defsym " "symbol" "\fR = \fP" expression
Create a global symbol in the output file, containing the absolute
address given by \c
.I expression\c
--- 460,466 ----
\& has the same effect.
.TP
! .BI "-defsym " "symbol" "\fR=\fP" expression
Create a global symbol in the output file, containing the absolute
address given by \c
.I expression\c
*************** relocations one output section will cont
*** 888,893 ****
--- 894,913 ----
Similar to
.B \-split\-by\-reloc
but creates a new output section for each input file.
+
+ .TP
+ .BI "--section-start " "sectionname" "\fR=\fP"org
+ Locate a section in the output file at the absolute
+ address given by \c
+ .I org\c
+ \&. \c
+ \c
+ .I org\c
+ \& must be a hexadecimal integer.
+ You may use this option as many
+ times as necessary to locate multiple sections in the command
+ line. 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
--- ld.texinfo Mon May 22 13:39:11 2000
*************** full debugging information by over 30 pe
*** 1143,1148 ****
--- 1143,1160 ----
trouble). The @samp{--traditional-format} switch tells @code{ld} to not
combine duplicate entries.
+ @kindex --section-start @var{sectionname}=@var{org}
+ @item --section-start @var{sectionname}=@var{org}
+ Locate a section in the output file at the absolute
+ address given by @var{org}. You may use this option as many
+ times as necessary to locate multiple sections in the command
+ line.
+ @var{org} must be a single hexadecimal integer;
+ for compatibility with other linkers, you may omit the leading
+ @samp{0x} usually associated with hexadecimal values. @emph{Note:} there
+ should be no white space between @var{sectionname}, the equals
+ sign (``@key{=}''), and @var{org}.
+
@kindex -Tbss @var{org}
@kindex -Tdata @var{org}
@kindex -Ttext @var{org}
=======================================================================
*** ../ld/lexsup.c Fri May 19 11:02:20 2000
--- lexsup.c Mon May 22 13:43:59 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)
*** 840,845 ****
--- 843,877 ----
ldfile_open_command_file (optarg);
parser_input = input_script;
yyparse ();
+ break;
+ case OPTION_SECTION_START:
+ {
+ char *optarg2;
+
+ /* Check for <something>=<somthing>... */
+ optarg2 = strchr (optarg, '=');
+ if (optarg2 == NULL)
+ {
+ fprintf (stderr,
+ _("%s: Invalid argument to option \"--section-start\"\n"),
+ program_name);
+ xexit (1);
+ }
+
+ *optarg2++ = '\0';
+
+ /* So far so good. Are all the args present? */
+ if ((*optarg == '\0') || (*optarg2 == '\0'))
+ {
+ fprintf (stderr,
+ _("%s: Missing argument(s) to option \"--section-start\"\n"),
+ program_name);
+ xexit (1);
+ }
+
+ /* Then set it... */
+ set_section_start (optarg, optarg2);
+ }
break;
case OPTION_TBSS:
set_section_start (".bss", optarg);
=======================================================================
More information about the Binutils
mailing list