Commit dec32c53 authored by John van Groningen's avatar John van Groningen

align pic symbol stubs to 36 bytes, to allow linking

with new gcc that generates 32 byte pic symbol stubs
parent b19078e0
......@@ -508,7 +508,7 @@ compute_module_offsets n_symbols xcoff_list4 marked_bool_a xcoff_a
= (text_offset,n_relocations,indirect_symbol_table_n,module_offsets,indirect_symbols);
compute_files_module_offsets [{n_symbols,symbol_table}:xcoff_list] text_offset file_n file_symbol_index n_relocations indirect_symbol_table_n module_offsets indirect_symbols
# (text_offset,n_relocations,indirect_symbol_table_n,module_offsets,indirect_symbols)
= compute_section_module_with_indirect_symbols_offsets symbol_table.stub_symbols file_n file_symbol_index symbol_table.symbols symbol_table.section_offsets text_offset n_relocations indirect_symbol_table_n module_offsets indirect_symbols;
= compute_stubs_section_module_with_indirect_symbols_offsets symbol_table.stub_symbols file_n file_symbol_index symbol_table.symbols symbol_table.section_offsets text_offset n_relocations indirect_symbol_table_n module_offsets indirect_symbols;
= compute_files_module_offsets xcoff_list text_offset (file_n+1) (file_symbol_index+n_symbols) n_relocations indirect_symbol_table_n module_offsets indirect_symbols;
}
......@@ -560,60 +560,82 @@ compute_module_offsets n_symbols xcoff_list4 marked_bool_a xcoff_a
# module_offsets = {module_offsets & [file_symbol_index+module_n]=module_offset};
# indirect_symbols = [(indirect_symbol_n,file_n,indirect_symbol_name):indirect_symbols];
= compute_section_module_with_indirect_symbols_offsets symbol_list file_n file_symbol_index symbol_array section_offsets offset1 n_relocations (indirect_symbol_table_n+1) module_offsets indirect_symbols;
compute_stubs_section_module_with_indirect_symbols_offsets :: SymbolIndexList Int Int SSymbolArray {#SectionAddressAndSymbolN} Int Int Int ModuleOffsets IndirectSymbols -> (!Int,!Int,!Int,!ModuleOffsets,!IndirectSymbols);
compute_stubs_section_module_with_indirect_symbols_offsets EmptySymbolIndex file_n file_symbol_index symbol_array section_offsets offset n_relocations indirect_symbol_table_n module_offsets indirect_symbols
= (offset,n_relocations,indirect_symbol_table_n,module_offsets,indirect_symbols);
compute_stubs_section_module_with_indirect_symbols_offsets (SymbolIndex module_n symbol_list) file_n file_symbol_index symbol_array=:{[module_n]=module_symbol} section_offsets offset0 n_relocations indirect_symbol_table_n module_offsets indirect_symbols
| not marked_bool_a.[file_symbol_index+module_n]
= compute_stubs_section_module_with_indirect_symbols_offsets symbol_list file_n file_symbol_index symbol_array section_offsets offset0 n_relocations indirect_symbol_table_n module_offsets indirect_symbols;
# (Module _ _ _ _ (IndirectSymbol indirect_symbol_n indirect_symbol_name) _ _) = module_symbol;
#! indirect_symbol_name = indirect_symbol_name
# (module_offset,offset1,n_relocations)=compute_stubs_module_offset_and_count_relocations module_symbol offset0 n_relocations symbol_array section_offsets;
# module_offsets = {module_offsets & [file_symbol_index+module_n]=module_offset};
# indirect_symbols = [(indirect_symbol_n,file_n,indirect_symbol_name):indirect_symbols];
= compute_stubs_section_module_with_indirect_symbols_offsets symbol_list file_n file_symbol_index symbol_array section_offsets offset1 n_relocations (indirect_symbol_table_n+1) module_offsets indirect_symbols;
compute_module_offset_and_count_relocations :: Symbol Int Int SSymbolArray {#SectionAddressAndSymbolN} -> (!Int,!Int,!Int);
compute_module_offset_and_count_relocations (Module section_n length _ _ _ old_n_module_relocations relocations) offset0 n_relocations symbol_array section_offsets
# alignment = 2;
# alignment=2;
alignment_mask=dec (1<<alignment);
aligned_offset0=(offset0+alignment_mask) bitand (bitnot alignment_mask);
# n_module_relocations = count_relocations 0 0;
with {
count_relocations relocation_n n_module_relocations
| relocation_n==old_n_module_relocations
= n_module_relocations;
# relocation_index=relocation_n * SIZE_OF_RELOCATION;
| relocations BYTE relocation_index bitand 0x80<>0 // r_scattered
# r_kind = relocations BYTE relocation_index;
# r_type=r_kind bitand 0xf;
| r_type==PPC_RELOC_BR24 || r_type==PPC_RELOC_BR14
# r_value=relocations ILONG (relocation_index+4);
# destination_section_n = determine_new_branch_section_n r_value section_offsets symbol_array xcoff_a;
| destination_section_n==section_n
= count_relocations (relocation_n+1) n_module_relocations;
= count_relocations (relocation_n+1) (n_module_relocations+1);
= count_relocations (relocation_n+1) (n_module_relocations+1);
# r_kind = relocations BYTE (relocation_index+7);
# r_type=r_kind bitand 0xf;
| r_type==PPC_RELOC_BR24
| r_kind bitand 0x10<>0 // r_extern
# relocation_symbol_n=relocations ITBYTE (relocation_index+4);
= case symbol_array.[relocation_symbol_n] of {
UndefinedLabel symbol_n
-> count_relocations (relocation_n+1) (n_module_relocations+1);
ImportedLabelPlusOffset symbol_file_n module_symbol_n label_offset
# (Module destination_section_n _ _ _ _ _ _) = xcoff_a.[symbol_file_n].symbol_table.symbols.[module_symbol_n];
| destination_section_n==section_n
-> count_relocations (relocation_n+1) n_module_relocations;
-> count_relocations (relocation_n+1) (n_module_relocations+1);
ImportedLabel symbol_file_n module_symbol_n
# (Module destination_section_n _ _ _ _ _ _) = xcoff_a.[symbol_file_n].symbol_table.symbols.[module_symbol_n];
| destination_section_n==section_n
-> count_relocations (relocation_n+1) n_module_relocations;
-> count_relocations (relocation_n+1) (n_module_relocations+1);
Module destination_section_n _ _ _ _ _ _
| destination_section_n==section_n
-> count_relocations (relocation_n+1) n_module_relocations;
-> count_relocations (relocation_n+1) (n_module_relocations+1);
_
-> count_relocations (relocation_n+1) (n_module_relocations+1);
};
= count_relocations (relocation_n+1) (n_module_relocations+1);
| r_type==PPC_RELOC_LO16 || r_type==PPC_RELOC_HA16
= count_relocations (relocation_n+2) (n_module_relocations+2);
| r_type==PPC_RELOC_VANILLA && r_kind bitand 0x60==0x40
= count_relocations (relocation_n+1) (n_module_relocations+1);
}
# n_module_relocations = count_relocations 0 0 section_n old_n_module_relocations relocations symbol_array section_offsets;
= (aligned_offset0,aligned_offset0+length,n_relocations+n_module_relocations);
compute_stubs_module_offset_and_count_relocations :: Symbol Int Int SSymbolArray {#SectionAddressAndSymbolN} -> (!Int,!Int,!Int);
compute_stubs_module_offset_and_count_relocations (Module section_n length _ _ _ old_n_module_relocations relocations) offset0 n_relocations symbol_array section_offsets
# n_module_relocations = count_relocations 0 0 section_n old_n_module_relocations relocations symbol_array section_offsets;
# aligned_length = ((length+STUB_SIZE-1) / STUB_SIZE) * STUB_SIZE;
= (offset0,offset0+aligned_length,n_relocations+n_module_relocations);
count_relocations relocation_n n_module_relocations section_n old_n_module_relocations relocations symbol_array section_offsets
= count_relocations relocation_n n_module_relocations;
{
count_relocations relocation_n n_module_relocations
| relocation_n==old_n_module_relocations
= n_module_relocations;
# relocation_index=relocation_n * SIZE_OF_RELOCATION;
| relocations BYTE relocation_index bitand 0x80<>0 // r_scattered
# r_kind = relocations BYTE relocation_index;
# r_type=r_kind bitand 0xf;
| r_type==PPC_RELOC_BR24 || r_type==PPC_RELOC_BR14
# r_value=relocations ILONG (relocation_index+4);
# destination_section_n = determine_new_branch_section_n r_value section_offsets symbol_array xcoff_a;
| destination_section_n==section_n
= count_relocations (relocation_n+1) n_module_relocations;
= count_relocations (relocation_n+1) (n_module_relocations+1);
= count_relocations (relocation_n+1) (n_module_relocations+1);
# r_kind = relocations BYTE (relocation_index+7);
# r_type=r_kind bitand 0xf;
| r_type==PPC_RELOC_BR24
| r_kind bitand 0x10<>0 // r_extern
# relocation_symbol_n=relocations ITBYTE (relocation_index+4);
= case symbol_array.[relocation_symbol_n] of {
UndefinedLabel symbol_n
-> count_relocations (relocation_n+1) (n_module_relocations+1);
ImportedLabelPlusOffset symbol_file_n module_symbol_n label_offset
# (Module destination_section_n _ _ _ _ _ _) = xcoff_a.[symbol_file_n].symbol_table.symbols.[module_symbol_n];
| destination_section_n==section_n
-> count_relocations (relocation_n+1) n_module_relocations;
-> count_relocations (relocation_n+1) (n_module_relocations+1);
ImportedLabel symbol_file_n module_symbol_n
# (Module destination_section_n _ _ _ _ _ _) = xcoff_a.[symbol_file_n].symbol_table.symbols.[module_symbol_n];
| destination_section_n==section_n
-> count_relocations (relocation_n+1) n_module_relocations;
-> count_relocations (relocation_n+1) (n_module_relocations+1);
Module destination_section_n _ _ _ _ _ _
| destination_section_n==section_n
-> count_relocations (relocation_n+1) n_module_relocations;
-> count_relocations (relocation_n+1) (n_module_relocations+1);
_
-> count_relocations (relocation_n+1) (n_module_relocations+1);
};
= count_relocations (relocation_n+1) (n_module_relocations+1);
| r_type==PPC_RELOC_LO16 || r_type==PPC_RELOC_HA16
= count_relocations (relocation_n+2) (n_module_relocations+2);
| r_type==PPC_RELOC_VANILLA && r_kind bitand 0x60==0x40
= count_relocations (relocation_n+1) (n_module_relocations+1);
}
}
write_relocation_strings [] output_file
......@@ -1264,7 +1286,7 @@ write_data_from_non_text_section_to_executable data_sections stub_sections lazy_
= (relocations,pe_file0);
write_stubs_from_object_files_to_executable [data_section_strings:data_section_list] [xcoff=:{n_symbols,symbol_table={stub_symbols,symbols,section_offsets,section_symbol_ns}}:xcoff_list] first_symbol_n offset0 relocations pe_file0
# (offset1,relocations,pe_file1)
= write_data_from_object_file_to_executable stub_symbols first_symbol_n offset0 symbols section_offsets section_symbol_ns data_section_strings relocations pe_file0;
= write_stub_code_from_object_file_to_executable stub_symbols first_symbol_n offset0 symbols section_offsets section_symbol_ns data_section_strings relocations pe_file0;
= write_stubs_from_object_files_to_executable data_section_list xcoff_list (first_symbol_n+n_symbols) offset1 relocations pe_file1;
write_lazy_pointers_from_object_files_to_executable :: [[*{#Char}]] [SXcoff] Int Int [String] *File -> (![String],!*File);
......@@ -1310,6 +1332,30 @@ write_data_from_non_text_section_to_executable data_sections stub_sections lazy_
= (aligned_offset0+length,new_relocations,fwrites data_a1 (write_zero_bytes_to_file (aligned_offset0-offset0) pe_file0));
}
write_stub_code_from_object_file_to_executable :: SymbolIndexList Int Int SSymbolArray {#SectionAddressAndSymbolN} {#Int} [*{#Char}] [String] *File -> (!Int,![String],!*File);
write_stub_code_from_object_file_to_executable EmptySymbolIndex first_symbol_n offset0 symbol_table section_offsets section_symbol_ns data_section_strings relocations pe_file0
= (offset0,relocations,pe_file0);
write_stub_code_from_object_file_to_executable (SymbolIndex module_n symbol_list) first_symbol_n offset0 symbol_table=:{[module_n] = symbol} section_offsets section_symbol_ns data_section_strings relocations pe_file0
| marked_bool_a.[first_symbol_n+module_n]
= case data_section_strings of {
[data_a0:data_section_strings]
# (offset1,module_relocations,pe_file1) = write_stub_module_to_pe_file symbol offset0 module_offset_a marked_offset_a xcoff_a data_a0 pe_file0;
# relocations = [module_relocations:relocations];
-> write_stub_code_from_object_file_to_executable symbol_list first_symbol_n offset1 symbol_table section_offsets section_symbol_ns data_section_strings relocations pe_file1;
};
= write_stub_code_from_object_file_to_executable symbol_list first_symbol_n offset0 symbol_table section_offsets section_symbol_ns data_section_strings relocations pe_file0;
{}{
write_stub_module_to_pe_file :: Symbol Int {#Int} {#Int} XcoffArray *{#Char} *File -> (!Int,!String,!*File);
write_stub_module_to_pe_file (Module section_n length virtual_address _ _ n_relocations relocations)
offset0 module_offset_a offset_a xcoff_a data_a0 pe_file0
# (real_module_offset,module_offset_a) = module_offset_a![first_symbol_n+module_n];
#! module_offset_a=module_offset_a;
# (data_a1,new_relocations) = relocate_text_or_data n_relocations virtual_address offset0 first_symbol_n section_n first_undefined_symbol_n
section_addresses section_offsets symbol_table module_offset_a relocations section_symbol_ns offset_a xcoff_a data_a0;
# aligned_length = ((length+STUB_SIZE-1) / STUB_SIZE) * STUB_SIZE;
= (offset0+aligned_length,new_relocations,write_zero_bytes_to_file (aligned_length-length) (fwrites data_a1 pe_file0));
}
}
(THEN) infixl;
......
......@@ -79,6 +79,8 @@ PPC_RELOC_SECTDIFF:==8;
PPC_RELOC_LO16_SECTDIFF:==11;
PPC_RELOC_HA16_SECTDIFF:==12;
STUB_SIZE:==36;
sort_modules :: !*SXcoff -> .SXcoff;
create_names_table :: NamesTable;
......
......@@ -192,7 +192,7 @@ write_mach_o_headers text_section_size_align_4 data_section_size_align_4 bss_sec
FWI n_stub_relocations
FWI (0x80000400 bitor S_SYMBOL_STUBS)
FWI 0
FWI 36;
FWI STUB_SIZE;
# file = file
FWS "__la_symbol_ptr\0"
FWS "__DATA\0\0\0\0\0\0\0\0\0\0"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment