Skip to content

Commit 8149bb1

Browse files
committed
Zero LMA/VMA of debug sections in elf. Closes rust-lang#148.
1 parent 4e37685 commit 8149bb1

File tree

1 file changed

+42
-105
lines changed

1 file changed

+42
-105
lines changed

src/boot/be/elf.ml

Lines changed: 42 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,16 @@ type sh_flags =
169169

170170

171171
let section_header
172+
?(sh_link:int64 option=None)
173+
?(sh_info:int64 option=None)
174+
?(zero_sh_addr:bool=false)
175+
?(sh_flags:sh_flags list=[])
176+
?(section_fixup:fixup option=None)
177+
?(sh_addralign:int64=1L)
178+
?(sh_entsize:int64=0L)
172179
~(shstring_table_fixup:fixup)
173180
~(shname_string_fixup:fixup)
174-
~(sh_type:sh_type)
175-
~(sh_flags:sh_flags list)
176-
~(section_fixup:fixup option)
177-
~(sh_addralign:int64)
178-
~(sh_entsize:int64)
179-
~(sh_link:int64 option)
180-
~(sh_info:int64 option)
181+
(sh_type:sh_type)
181182
: frag =
182183
SEQ
183184
[|
@@ -202,9 +203,12 @@ let section_header
202203
SHF_WRITE -> 0x1L
203204
| SHF_ALLOC -> 0x2L
204205
| SHF_EXECINSTR -> 0x4L) sh_flags)));
205-
WORD (TY_u32, (match section_fixup with
206-
None -> (IMM 0L)
207-
| Some s -> (M_POS s)));
206+
WORD (TY_u32,
207+
if zero_sh_addr
208+
then IMM 0L
209+
else (match section_fixup with
210+
None -> (IMM 0L)
211+
| Some s -> (M_POS s)));
208212
WORD (TY_u32, (match section_fixup with
209213
None -> (IMM 0L)
210214
| Some s -> (F_POS s)));
@@ -693,169 +697,129 @@ let elf32_linux_x86_file
693697
(section_header
694698
~shstring_table_fixup: shstrtab_section_fixup
695699
~shname_string_fixup: null_section_name_fixup
696-
~sh_type: SHT_NULL
697-
~sh_flags: []
698700
~section_fixup: None
699701
~sh_addralign: 0L
700-
~sh_entsize: 0L
701-
~sh_link: None
702-
~sh_info: None);
702+
SHT_NULL);
703703

704704
(* .interp *)
705705
(section_header
706706
~shstring_table_fixup: shstrtab_section_fixup
707707
~shname_string_fixup: interp_section_name_fixup
708-
~sh_type: SHT_PROGBITS
709708
~sh_flags: [ SHF_ALLOC ]
710709
~section_fixup: (Some interp_section_fixup)
711-
~sh_addralign: 1L
712-
~sh_entsize: 0L
713-
~sh_link: None
714-
~sh_info: None);
710+
SHT_PROGBITS);
715711

716712
(* .text *)
717713
(section_header
718714
~shstring_table_fixup: shstrtab_section_fixup
719715
~shname_string_fixup: text_section_name_fixup
720-
~sh_type: SHT_PROGBITS
721716
~sh_flags: [ SHF_ALLOC; SHF_EXECINSTR ]
722717
~section_fixup: (Some text_section_fixup)
723718
~sh_addralign: 32L
724-
~sh_entsize: 0L
725-
~sh_link: None
726-
~sh_info: None);
719+
SHT_PROGBITS);
727720

728721
(* .rodata *)
729722
(section_header
730723
~shstring_table_fixup: shstrtab_section_fixup
731724
~shname_string_fixup: rodata_section_name_fixup
732-
~sh_type: SHT_PROGBITS
733725
~sh_flags: [ SHF_ALLOC ]
734726
~section_fixup: (Some rodata_section_fixup)
735727
~sh_addralign: 32L
736-
~sh_entsize: 0L
737-
~sh_link: None
738-
~sh_info: None);
728+
SHT_PROGBITS);
739729

740730
(* .dynsym *)
741731
(section_header
742732
~shstring_table_fixup: shstrtab_section_fixup
743733
~shname_string_fixup: dynsym_section_name_fixup
744-
~sh_type: SHT_DYNSYM
745734
~sh_flags: [ SHF_ALLOC ]
746735
~section_fixup: (Some dynsym_section_fixup)
747736
~sh_addralign: 4L
748737
~sh_entsize: elf32_symsize
749738
~sh_link: (Some dynstrndx)
750-
~sh_info: None );
739+
SHT_DYNSYM);
751740

752741
(* .dynstr *)
753742
(section_header
754743
~shstring_table_fixup: shstrtab_section_fixup
755744
~shname_string_fixup: dynstr_section_name_fixup
756-
~sh_type: SHT_STRTAB
757745
~sh_flags: [ SHF_ALLOC ]
758746
~section_fixup: (Some dynstr_section_fixup)
759-
~sh_addralign: 1L
760-
~sh_entsize: 0L
761-
~sh_link: None
762-
~sh_info: None);
747+
SHT_STRTAB);
763748

764749
(* .hash *)
765750
(section_header
766751
~shstring_table_fixup: shstrtab_section_fixup
767752
~shname_string_fixup: hash_section_name_fixup
768-
~sh_type: SHT_PROGBITS
769753
~sh_flags: [ SHF_ALLOC ]
770754
~section_fixup: (Some hash_section_fixup)
771755
~sh_addralign: 4L
772756
~sh_entsize: 4L
773-
~sh_link: (Some dynsymndx)
774-
~sh_info: None);
757+
SHT_PROGBITS);
775758

776759
(* .plt *)
777760
(section_header
778761
~shstring_table_fixup: shstrtab_section_fixup
779762
~shname_string_fixup: plt_section_name_fixup
780-
~sh_type: SHT_PROGBITS
781763
~sh_flags: [ SHF_ALLOC; SHF_EXECINSTR ]
782764
~section_fixup: (Some plt_section_fixup)
783765
~sh_addralign: 4L
784-
~sh_entsize: 0L
785-
~sh_link: None
786-
~sh_info: None);
766+
SHT_PROGBITS);
787767

788768
(* .got.plt *)
789769
(section_header
790770
~shstring_table_fixup: shstrtab_section_fixup
791771
~shname_string_fixup: got_plt_section_name_fixup
792-
~sh_type: SHT_PROGBITS
793772
~sh_flags: [ SHF_ALLOC; SHF_WRITE ]
794773
~section_fixup: (Some got_plt_section_fixup)
795774
~sh_addralign: 4L
796-
~sh_entsize: 0L
797-
~sh_link: None
798-
~sh_info: None);
775+
SHT_PROGBITS);
799776

800777
(* .rela.plt *)
801778
(section_header
802779
~shstring_table_fixup: shstrtab_section_fixup
803780
~shname_string_fixup: rela_plt_section_name_fixup
804-
~sh_type: SHT_RELA
805781
~sh_flags: [ SHF_ALLOC ]
806782
~section_fixup: (Some rela_plt_section_fixup)
807783
~sh_addralign: 4L
808784
~sh_entsize: elf32_rela_entsz
809785
~sh_link: (Some dynsymndx)
810-
~sh_info: (Some pltndx));
786+
~sh_info: (Some pltndx)
787+
SHT_RELA);
811788

812789
(* .data *)
813790
(section_header
814791
~shstring_table_fixup: shstrtab_section_fixup
815792
~shname_string_fixup: data_section_name_fixup
816-
~sh_type: SHT_PROGBITS
817793
~sh_flags: [ SHF_ALLOC; SHF_WRITE ]
818794
~section_fixup: (Some data_section_fixup)
819795
~sh_addralign: 32L
820-
~sh_entsize: 0L
821-
~sh_link: None
822-
~sh_info: None);
796+
SHT_PROGBITS);
823797

824798
(* .bss *)
825799
(section_header
826800
~shstring_table_fixup: shstrtab_section_fixup
827801
~shname_string_fixup: bss_section_name_fixup
828-
~sh_type: SHT_NOBITS
829802
~sh_flags: [ SHF_ALLOC; SHF_WRITE ]
830803
~section_fixup: (Some bss_section_fixup)
831804
~sh_addralign: 32L
832-
~sh_entsize: 0L
833-
~sh_link: None
834-
~sh_info: None);
805+
SHT_NOBITS);
835806

836807
(* .dynamic *)
837808
(section_header
838809
~shstring_table_fixup: shstrtab_section_fixup
839810
~shname_string_fixup: dynamic_section_name_fixup
840-
~sh_type: SHT_DYNAMIC
841811
~sh_flags: [ SHF_ALLOC; SHF_WRITE ]
842812
~section_fixup: (Some dynamic_section_fixup)
843813
~sh_addralign: 8L
844-
~sh_entsize: 0L
845814
~sh_link: (Some dynstrndx)
846-
~sh_info: None);
815+
SHT_DYNAMIC);
847816

848817
(* .shstrtab *)
849818
(section_header
850819
~shstring_table_fixup: shstrtab_section_fixup
851820
~shname_string_fixup: shstrtab_section_name_fixup
852-
~sh_type: SHT_STRTAB
853-
~sh_flags: []
854821
~section_fixup: (Some shstrtab_section_fixup)
855-
~sh_addralign: 1L
856-
~sh_entsize: 0L
857-
~sh_link: None
858-
~sh_info: None);
822+
SHT_STRTAB);
859823

860824
(*
861825
FIXME: uncomment the dwarf section headers as you make use of them;
@@ -869,91 +833,64 @@ let elf32_linux_x86_file
869833
(section_header
870834
~shstring_table_fixup: shstrtab_section_fixup
871835
~shname_string_fixup: debug_aranges_section_name_fixup
872-
~sh_type: SHT_PROGBITS
873-
~sh_flags: []
874836
~section_fixup: (Some sem.Semant.ctxt_debug_aranges_fixup)
875837
~sh_addralign: 8L
876-
~sh_entsize: 0L
877-
~sh_link: None
878-
~sh_info: None);
838+
~zero_sh_addr: true
839+
SHT_PROGBITS);
879840
*)
880841
(* .debug_pubnames *)
881842
(*
882843
(section_header
883844
~shstring_table_fixup: shstrtab_section_fixup
884845
~shname_string_fixup: debug_pubnames_section_name_fixup
885-
~sh_type: SHT_PROGBITS
886-
~sh_flags: []
887846
~section_fixup: (Some sem.Semant.ctxt_debug_pubnames_fixup)
888-
~sh_addralign: 1L
889-
~sh_entsize: 0L
890-
~sh_link: None
891-
~sh_info: None);
847+
~zero_sh_addr: true
848+
SHT_PROGBITS);
892849
*)
893850

894851
(* .debug_info *)
895852
(section_header
896853
~shstring_table_fixup: shstrtab_section_fixup
897854
~shname_string_fixup: debug_info_section_name_fixup
898-
~sh_type: SHT_PROGBITS
899-
~sh_flags: []
900855
~section_fixup: (Some sem.Semant.ctxt_debug_info_fixup)
901-
~sh_addralign: 1L
902-
~sh_entsize: 0L
903-
~sh_link: None
904-
~sh_info: None);
856+
~zero_sh_addr: true
857+
SHT_PROGBITS);
905858

906859
(* .debug_abbrev *)
907860
(section_header
908861
~shstring_table_fixup: shstrtab_section_fixup
909862
~shname_string_fixup: debug_abbrev_section_name_fixup
910-
~sh_type: SHT_PROGBITS
911-
~sh_flags: []
912863
~section_fixup: (Some sem.Semant.ctxt_debug_abbrev_fixup)
913-
~sh_addralign: 1L
914-
~sh_entsize: 0L
915-
~sh_link: None
916-
~sh_info: None);
864+
~zero_sh_addr: true
865+
SHT_PROGBITS);
917866

918867
(* .debug_line *)
919868
(*
920869
(section_header
921870
~shstring_table_fixup: shstrtab_section_fixup
922871
~shname_string_fixup: debug_line_section_name_fixup
923-
~sh_type: SHT_PROGBITS
924-
~sh_flags: []
925872
~section_fixup: (Some sem.Semant.ctxt_debug_line_fixup)
926-
~sh_addralign: 1L
927-
~sh_entsize: 0L
928-
~sh_link: None
929-
~sh_info: None);
873+
~zero_sh_addr: true
874+
SHT_PROGBITS);
930875
*)
931876

932877
(* .debug_frame *)
933878
(*
934879
(section_header
935880
~shstring_table_fixup: shstrtab_section_fixup
936881
~shname_string_fixup: debug_frame_section_name_fixup
937-
~sh_type: SHT_PROGBITS
938-
~sh_flags: []
939882
~section_fixup: (Some sem.Semant.ctxt_debug_frame_fixup)
940883
~sh_addralign: 4L
941-
~sh_entsize: 0L
942-
~sh_link: None
943-
~sh_info: None);
884+
~zero_sh_addr: true
885+
SHT_PROGBITS);
944886
*)
945887

946888
(* .note.rust *)
947889
(section_header
948890
~shstring_table_fixup: shstrtab_section_fixup
949891
~shname_string_fixup: note_rust_section_name_fixup
950-
~sh_type: SHT_NOTE
951-
~sh_flags: []
952892
~section_fixup: (Some note_rust_section_fixup)
953-
~sh_addralign: 1L
954-
~sh_entsize: 0L
955-
~sh_link: None
956-
~sh_info: None);
893+
SHT_NOTE);
957894

958895
|]
959896
in

0 commit comments

Comments
 (0)