aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Choi2003-10-31 19:42:47 +0000
committerAndrew Choi2003-10-31 19:42:47 +0000
commit043131c4a79050465f9a7ca7b0d795acac470a0c (patch)
tree7988fdfbe77424c9a894c818339974ea8d35e847 /src
parent6d59ebc35cc3bdb50506491b104d493640fb7da7 (diff)
downloademacs-043131c4a79050465f9a7ca7b0d795acac470a0c.tar.gz
emacs-043131c4a79050465f9a7ca7b0d795acac470a0c.zip
These are Nozomu Ando's changes to build Emacs to run under X Window
in Mac OS X without the need to use static X11 libraries.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/unexmacosx.c79
2 files changed, 81 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index be63443b4bf..05d375e5da3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12003-10-31 Andrew Choi <akochoi@shaw.ca>
2
3 * unexmacosx.c (unrelocate): New function (contributed by Nozomu
4 Ando).
5 (copy_dysymtab): Call it.
6
12003-10-31 Luc Teirlinck <teirllm@auburn.edu> 72003-10-31 Luc Teirlinck <teirllm@auburn.edu>
2 8
3 * eval.c (Fdefvaralias): Doc fix. 9 * eval.c (Fdefvaralias): Doc fix.
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index d3afaf47cc1..b8532325973 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -95,6 +95,10 @@ Boston, MA 02111-1307, USA. */
95#include <unistd.h> 95#include <unistd.h>
96#include <mach/mach.h> 96#include <mach/mach.h>
97#include <mach-o/loader.h> 97#include <mach-o/loader.h>
98#include <mach-o/reloc.h>
99#if defined (__ppc__)
100#include <mach-o/ppc/reloc.h>
101#endif
98#include <objc/malloc.h> 102#include <objc/malloc.h>
99 103
100#define VERBOSE 1 104#define VERBOSE 1
@@ -158,6 +162,11 @@ int in_dumped_exec = 0;
158 162
159malloc_zone_t *emacs_zone; 163malloc_zone_t *emacs_zone;
160 164
165/* file offset of input file's data segment */
166off_t data_segment_old_fileoff;
167
168struct segment_command *data_segment_scp;
169
161/* Read n bytes from infd into memory starting at address dest. 170/* Read n bytes from infd into memory starting at address dest.
162 Return true if successful, false otherwise. */ 171 Return true if successful, false otherwise. */
163static int 172static int
@@ -763,6 +772,65 @@ copy_symtab (struct load_command *lc)
763 curr_header_offset += lc->cmdsize; 772 curr_header_offset += lc->cmdsize;
764} 773}
765 774
775/* Fix up relocation entries. */
776static void
777unrelocate (const char *name, off_t reloff, int nrel)
778{
779 int i, unreloc_count;
780 struct relocation_info reloc_info;
781 struct scattered_relocation_info *sc_reloc_info
782 = (struct scattered_relocation_info *) &reloc_info;
783
784 for (unreloc_count = 0, i = 0; i < nrel; i++)
785 {
786 if (lseek (infd, reloff, L_SET) != reloff)
787 unexec_error ("unrelocate: %s:%d cannot seek to reloc_info", name, i);
788 if (!unexec_read (&reloc_info, sizeof (reloc_info)))
789 unexec_error ("unrelocate: %s:%d cannot read reloc_info", name, i);
790 reloff += sizeof (reloc_info);
791
792 if (sc_reloc_info->r_scattered == 0)
793 switch (reloc_info.r_type)
794 {
795 case GENERIC_RELOC_VANILLA:
796 if (reloc_info.r_address >= data_segment_scp->vmaddr
797 && reloc_info.r_address < (data_segment_scp->vmaddr
798 + data_segment_scp->vmsize))
799 {
800 off_t src_off = data_segment_old_fileoff
801 + reloc_info.r_address - data_segment_scp->vmaddr;
802 off_t dst_off = data_segment_scp->fileoff
803 + reloc_info.r_address - data_segment_scp->vmaddr;
804
805 if (!unexec_copy (dst_off, src_off, 1 << reloc_info.r_length))
806 unexec_error ("unrelocate: %s:%d cannot copy original value",
807 name, i);
808 unreloc_count++;
809 }
810 break;
811 default:
812 unexec_error ("unrelocate: %s:%d cannot handle type = %d",
813 name, i, reloc_info.r_type);
814 }
815 else
816 switch (sc_reloc_info->r_type)
817 {
818#if defined (__ppc__)
819 case PPC_RELOC_PB_LA_PTR:
820 /* nothing to do for prebound lazy pointer */
821 break;
822#endif
823 default:
824 unexec_error ("unrelocate: %s:%d cannot handle scattered type = %d",
825 name, i, sc_reloc_info->r_type);
826 }
827 }
828
829 if (nrel > 0)
830 printf ("Fixed up %d/%d %s relocation entries in data segment.\n",
831 unreloc_count, nrel, name);
832}
833
766/* Copy a LC_DYSYMTAB load command from the input file to the output 834/* Copy a LC_DYSYMTAB load command from the input file to the output
767 file, adjusting the file offset fields. */ 835 file, adjusting the file offset fields. */
768static void 836static void
@@ -770,10 +838,8 @@ copy_dysymtab (struct load_command *lc)
770{ 838{
771 struct dysymtab_command *dstp = (struct dysymtab_command *) lc; 839 struct dysymtab_command *dstp = (struct dysymtab_command *) lc;
772 840
773 /* If Mach-O executable is not prebound, relocation entries need 841 unrelocate ("local", dstp->locreloff, dstp->nlocrel);
774 fixing up. This is not supported currently. */ 842 unrelocate ("external", dstp->extreloff, dstp->nextrel);
775 if (!(mh.flags & MH_PREBOUND) && (dstp->nextrel != 0 || dstp->nlocrel != 0))
776 unexec_error ("cannot handle LC_DYSYMTAB with relocation entries");
777 843
778 if (dstp->nextrel > 0) { 844 if (dstp->nextrel > 0) {
779 dstp->extreloff += delta; 845 dstp->extreloff += delta;
@@ -845,6 +911,11 @@ dump_it ()
845 struct segment_command *scp = (struct segment_command *) lca[i]; 911 struct segment_command *scp = (struct segment_command *) lca[i];
846 if (strncmp (scp->segname, SEG_DATA, 16) == 0) 912 if (strncmp (scp->segname, SEG_DATA, 16) == 0)
847 { 913 {
914 /* save data segment file offset and segment_command for
915 unrelocate */
916 data_segment_old_fileoff = scp->fileoff;
917 data_segment_scp = scp;
918
848 copy_data_segment (lca[i]); 919 copy_data_segment (lca[i]);
849 } 920 }
850 else 921 else