* ldgram.y: map -M behave in the same way as -Map (sets file name
to be "-". * ldsym.c, ldlang.c: remember that size of a section is dependent on whether or not relaxing has been done. * ldmain.c: don't open a map file if it doesn't have a name * relax.c: all the brains have moved into bfd. * ldwrite.c: ammend comment
This commit is contained in:
parent
daa91756f1
commit
870f54b2c8
5 changed files with 65 additions and 189 deletions
10
ld/ChangeLog
10
ld/ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Tue Jan 28 10:18:16 1992 Steve Chamberlain (sac at rtl.cygnus.com)
|
||||
|
||||
* ldgram.y: map -M behave in the same way as -Map (sets file name
|
||||
to be "-".
|
||||
* ldsym.c, ldlang.c: remember that size of a section is dependent on
|
||||
whether or not relaxing has been done.
|
||||
* ldmain.c: don't open a map file if it doesn't have a name
|
||||
* relax.c: all the brains have moved into bfd.
|
||||
* ldwrite.c: ammend comment
|
||||
|
||||
Fri Jan 24 14:23:46 1992 Steve Chamberlain (sac at rtl.cygnus.com)
|
||||
|
||||
* Makefile.in: added relax, also made three stage go through a
|
||||
|
|
|
@ -193,11 +193,8 @@ command_line_option:
|
|||
}
|
||||
|
||||
| OPTION_M {
|
||||
if (write_map) {
|
||||
option_longmap = true;
|
||||
}
|
||||
write_map = true;
|
||||
|
||||
config.map_filename = "-";
|
||||
|
||||
}
|
||||
| OPTION_n {
|
||||
config.magic_demand_paged = false;
|
||||
|
|
95
ld/ldmain.c
95
ld/ldmain.c
|
@ -129,21 +129,21 @@ main (argc, argv)
|
|||
|
||||
bfd_init();
|
||||
#ifdef GNU960
|
||||
{
|
||||
int i;
|
||||
{
|
||||
int i;
|
||||
|
||||
check_v960( argc, argv );
|
||||
emulation = GLD960_EMULATION_NAME;
|
||||
for ( i = 1; i < argc; i++ ){
|
||||
if ( !strcmp(argv[i],"-Fcoff") ){
|
||||
emulation = LNK960_EMULATION_NAME;
|
||||
output_flavor = BFD_COFF_FORMAT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
check_v960( argc, argv );
|
||||
emulation = GLD960_EMULATION_NAME;
|
||||
for ( i = 1; i < argc; i++ ){
|
||||
if ( !strcmp(argv[i],"-Fcoff") ){
|
||||
emulation = LNK960_EMULATION_NAME;
|
||||
output_flavor = BFD_COFF_FORMAT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
emulation = (char *) getenv(EMULATION_ENVIRON);
|
||||
emulation = (char *) getenv(EMULATION_ENVIRON);
|
||||
#endif
|
||||
|
||||
/* Initialize the data about options. */
|
||||
|
@ -172,8 +172,8 @@ main (argc, argv)
|
|||
config.text_read_only = true;
|
||||
config.make_executable = true;
|
||||
if (emulation == (char *)NULL) {
|
||||
emulation= DEFAULT_EMULATION;
|
||||
}
|
||||
emulation= DEFAULT_EMULATION;
|
||||
}
|
||||
|
||||
ldemul_choose_mode(emulation);
|
||||
default_target = ldemul_choose_target();
|
||||
|
@ -183,15 +183,21 @@ main (argc, argv)
|
|||
parse_args(argc, argv);
|
||||
lang_final();
|
||||
if (trace_files) {
|
||||
info("%P: mode %s\n", emulation);
|
||||
}
|
||||
info("%P: mode %s\n", emulation);
|
||||
}
|
||||
if (lang_has_input_file == false) {
|
||||
einfo("%P%F: No input files\n");
|
||||
}
|
||||
einfo("%P%F: No input files\n");
|
||||
}
|
||||
|
||||
ldemul_after_parse();
|
||||
if (config.map_filename)
|
||||
{
|
||||
|
||||
if (config.map_filename)
|
||||
{
|
||||
if (strcmp(config.map_filename[0],"-") == 0)
|
||||
{
|
||||
config.map_file = stdout;
|
||||
}
|
||||
else {
|
||||
config.map_file = fopen(config.map_filename, FOPEN_WT);
|
||||
if (config.map_file == (FILE *)NULL)
|
||||
{
|
||||
|
@ -199,7 +205,8 @@ main (argc, argv)
|
|||
config.map_filename);
|
||||
}
|
||||
}
|
||||
else config.map_file = stdout;
|
||||
}
|
||||
|
||||
|
||||
lang_process();
|
||||
|
||||
|
@ -208,35 +215,35 @@ main (argc, argv)
|
|||
|
||||
|
||||
if (config.text_read_only) {
|
||||
/* Look for a text section and mark the readonly attribute in it */
|
||||
asection *found = bfd_get_section_by_name(output_bfd, ".text");
|
||||
if (found == (asection *)NULL) {
|
||||
einfo("%P%F: text marked read only, but no text section present");
|
||||
/* Look for a text section and mark the readonly attribute in it */
|
||||
asection *found = bfd_get_section_by_name(output_bfd, ".text");
|
||||
if (found == (asection *)NULL) {
|
||||
einfo("%P%F: text marked read only, but no text section present");
|
||||
}
|
||||
found->flags |= SEC_READONLY;
|
||||
}
|
||||
found->flags |= SEC_READONLY;
|
||||
}
|
||||
|
||||
if (config.relocateable_output) {
|
||||
output_bfd->flags &= ~EXEC_P;
|
||||
output_bfd->flags &= ~EXEC_P;
|
||||
|
||||
ldwrite();
|
||||
bfd_close(output_bfd);
|
||||
}
|
||||
else {
|
||||
output_bfd->flags |= EXEC_P;
|
||||
|
||||
ldwrite();
|
||||
|
||||
if (config.make_executable == false && force_make_executable ==false) {
|
||||
|
||||
unlink(output_filename);
|
||||
ldwrite();
|
||||
bfd_close(output_bfd);
|
||||
}
|
||||
else {
|
||||
output_bfd->flags |= EXEC_P;
|
||||
|
||||
ldwrite();
|
||||
|
||||
if (config.make_executable == false && force_make_executable ==false) {
|
||||
|
||||
unlink(output_filename);
|
||||
}
|
||||
else { bfd_close(output_bfd); };
|
||||
return (!config.make_executable);
|
||||
}
|
||||
else { bfd_close(output_bfd); };
|
||||
return (!config.make_executable);
|
||||
}
|
||||
|
||||
return(0);
|
||||
} /* main() */
|
||||
} /* main() */
|
||||
|
||||
|
||||
void
|
||||
|
|
|
@ -227,7 +227,7 @@ DEFUN(print_file_stuff,(f),
|
|||
s != (asection *)NULL;
|
||||
s = s->next) {
|
||||
print_address(s->output_offset);
|
||||
if (s->flags & SEC_HAS_CONTENTS)
|
||||
if (s->reloc_done)
|
||||
{
|
||||
fprintf (config.map_file, " %08x 2**%2ud %s\n",
|
||||
(unsigned)bfd_get_section_size_after_reloc(s),
|
||||
|
|
140
ld/relax.c
140
ld/relax.c
|
@ -141,99 +141,6 @@ DEFUN(write_relaxnorel,(output_bfd),
|
|||
|
||||
|
||||
|
||||
static void
|
||||
DEFUN(perform_slip,(s, slip, input_section, value),
|
||||
asymbol **s AND
|
||||
unsigned int slip AND
|
||||
asection *input_section AND
|
||||
bfd_vma value)
|
||||
{
|
||||
|
||||
/* Find all symbols past this point, and make them know
|
||||
what's happened */
|
||||
while (*s)
|
||||
{
|
||||
asymbol *p = *s;
|
||||
if (p->section == input_section)
|
||||
{
|
||||
/* This was pointing into this section, so mangle it */
|
||||
if (p->value > value)
|
||||
{
|
||||
p->value -=2;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
|
||||
}
|
||||
}
|
||||
static int
|
||||
DEFUN(movb1,(input_section, symbols, r, shrink),
|
||||
asection *input_section AND
|
||||
asymbol **symbols AND
|
||||
arelent *r AND
|
||||
unsigned int shrink)
|
||||
{
|
||||
|
||||
|
||||
bfd_vma value = get_value(r, input_section);
|
||||
|
||||
if (value >= 0xff00)
|
||||
{
|
||||
|
||||
/* Change the reloc type from 16bit, possible 8 to 8bit
|
||||
possible 16 */
|
||||
r->howto = r->howto + 1;
|
||||
/* The place to relc moves back by one */
|
||||
r->address -=1;
|
||||
|
||||
/* This will be two bytes smaller in the long run */
|
||||
shrink +=2 ;
|
||||
perform_slip(symbols, 2, input_section, r->address - shrink +1);
|
||||
|
||||
|
||||
}
|
||||
return shrink;
|
||||
}
|
||||
|
||||
static int
|
||||
DEFUN(jmp1,(input_section, symbols, r, shrink),
|
||||
asection *input_section AND
|
||||
asymbol **symbols AND
|
||||
arelent *r AND
|
||||
unsigned int shrink)
|
||||
{
|
||||
|
||||
|
||||
bfd_vma value = get_value(r, 0);
|
||||
|
||||
bfd_vma dot = input_section->output_section->vma +
|
||||
input_section->output_offset + r->address;
|
||||
bfd_vma gap;
|
||||
|
||||
/* See if the address we're looking at within 127 bytes of where
|
||||
we are, if so then we can use a small branch rather than the
|
||||
jump we were going to */
|
||||
|
||||
gap = value - (dot - shrink);
|
||||
|
||||
|
||||
if (-120 < (long)gap && (long)gap < 120 )
|
||||
{
|
||||
|
||||
/* Change the reloc type from 16bit, possible 8 to 8bit
|
||||
possible 16 */
|
||||
r->howto = r->howto + 1;
|
||||
/* The place to relc moves back by one */
|
||||
r->address -=1;
|
||||
|
||||
/* This will be two bytes smaller in the long run */
|
||||
shrink +=2 ;
|
||||
perform_slip(symbols, 2, input_section, r->address-shrink +1);
|
||||
|
||||
|
||||
}
|
||||
return shrink;
|
||||
}
|
||||
|
||||
|
||||
/* See if we can change the size of this section by shrinking the
|
||||
|
@ -248,52 +155,7 @@ DEFUN(relax_section,(this_ptr),
|
|||
lang_input_section_type *is = &((*this_ptr)->input_section);
|
||||
asection *i = is->section;
|
||||
|
||||
|
||||
/* Get enough memory to hold the stuff */
|
||||
bfd *input_bfd = i->owner;
|
||||
asection *input_section = i;
|
||||
int shrink = 0 ;
|
||||
int new = 0;
|
||||
|
||||
bfd_size_type reloc_size = bfd_get_reloc_upper_bound(input_bfd,
|
||||
input_section);
|
||||
arelent **reloc_vector = (arelent **)ldmalloc(reloc_size);
|
||||
|
||||
/* Get the relocs and think about them */
|
||||
if (bfd_canonicalize_reloc(input_bfd,
|
||||
input_section,
|
||||
reloc_vector,
|
||||
is->ifile->asymbols) )
|
||||
{
|
||||
arelent **parent;
|
||||
asymbol **symbols = is->ifile->asymbols;
|
||||
for (parent = reloc_vector; *parent; parent++)
|
||||
{
|
||||
arelent *r = *parent;
|
||||
switch (r->howto->type) {
|
||||
case R_MOVB2:
|
||||
case R_JMP2:
|
||||
|
||||
shrink+=2;
|
||||
break;
|
||||
|
||||
case R_MOVB1:
|
||||
shrink = movb1(input_section, symbols, r, shrink);
|
||||
new = 1;
|
||||
|
||||
break;
|
||||
case R_JMP1:
|
||||
shrink = jmp1(input_section, symbols, r, shrink);
|
||||
new = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
input_section->_cooked_size -= shrink;
|
||||
free((char *)reloc_vector);
|
||||
return new;
|
||||
return bfd_relax_section(i->owner, i, is->ifile->asymbols);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue