glenne%hplsla@HPLABS.HP.COM (Glenn Engel) (02/16/89)
This patch adds the capability to relocate the data segment start address. I've successfully used this patched ld to burn roms for our rom-based prototype. The flag "R" is used to specify the address, much like the "T" option. (The use of "R", of course, is arbitrary.) I'm also checking for overlapping segments, assuming the data and bss segments occupy a contiguous area. A check is made to see that the text doesn't run into the data area and vice versa. -- bam bam%hplsla@hplabs.hp.com (In Real Life: Ben Mejia at HP Lake Stevens Instrument Division) (206) 335-2203 "May the forces of evil become confused on the way to your house." -- George Carlin --- snip ---- *** ld-1.27.c.orig Thu Feb 9 12:03:28 1989 --- ld.c Thu Feb 9 11:26:31 1989 *************** *** 409,414 This prevents text_start from being set later to default values. */ int T_flag_specified; /* Size to pad data section up to. We simply increase the size of the data section, padding with zeros, and reduce the size of the bss section to match. */ --- 409,418 ----- This prevents text_start from being set later to default values. */ int T_flag_specified; + /* Nonzero if -R was specified in the command line. + This prevents data_start from being set later to default values. */ + int R_flag_specified; + /* Size to pad data section up to. We simply increase the size of the data section, padding with zeros, and reduce the size of the bss section to match. */ *************** *** 592,597 relocatable_output = 0; force_common_definition = 0; T_flag_specified = 0; magic = ZMAGIC; #ifdef hp9000s300 magic = NMAGIC; /* hp-ux bug screws ZMAGIC */ --- 596,602 ----- relocatable_output = 0; force_common_definition = 0; T_flag_specified = 0; + R_flag_specified = 0; magic = ZMAGIC; #ifdef hp9000s300 magic = NMAGIC; /* hp-ux bug screws ZMAGIC */ *************** *** 688,693 case 'L': case 'l': case 'o': case 'T': case 'u': case 'y': --- 693,699 ----- case 'L': case 'l': case 'o': + case 'R': case 'T': case 'u': case 'y': *************** *** 867,872 output_filename = arg; return; case 'r': relocatable_output = 1; magic = OMAGIC; --- 873,883 ----- output_filename = arg; return; + case 'R': + data_start = parse (arg, "%x", "invalid argument to -R"); + R_flag_specified = 1; + return; + case 'r': relocatable_output = 1; magic = OMAGIC; *************** *** 2143,2149 outheader.a_text = text_size; ! /* Make the data segment address start in memory on a suitable boundary. */ data_start = N_DATADDR (outheader) + text_start - N_TXTADDR (outheader); --- 2154,2161 ----- outheader.a_text = text_size; ! /* Use the data segment address specified by the -R flag or select */ ! /* a data segment address on a suitable boundary. */ if (!R_flag_specified) data_start = N_DATADDR (outheader) + text_start - N_TXTADDR (outheader); *************** *** 2145,2151 /* Make the data segment address start in memory on a suitable boundary. */ ! data_start = N_DATADDR (outheader) + text_start - N_TXTADDR (outheader); /* Compute start addresses of each file's sections and symbols. */ --- 2157,2169 ----- /* Use the data segment address specified by the -R flag or select */ /* a data segment address on a suitable boundary. */ ! if (!R_flag_specified) ! data_start = N_DATADDR (outheader) + text_start - N_TXTADDR (outheader); ! else ! if ((data_start < ! N_DATADDR (outheader) + text_start - N_TXTADDR (outheader)) && ! (data_start + data_size + bss_size > text_start)) ! fatal ("Segments overlap."); /* Compute start addresses of each file's sections and symbols. */