Patching NASM for Mac support.

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Post Reply
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Patching NASM for Mac support.

Post by Nach »

It's still not in NASM's official CVS for some reason, but thanks to Google code search, I found the latest one from Apple's server which contains hector's patches.

Patch against http://nasm.cvs.sourceforge.net/*checko ... vision=1.7

Code: Select all

--- outmacho.old        2006-10-06 07:40:58.000000000 +0200
+++ outmacho.c  2006-06-26 06:14:12.000000000 +0300
@@ -539,7 +539,7 @@
                 s->data = saa_init(1L);
                 s->index = seg_alloc();
                 s->relocs = NULL;
-                s->align = DEFAULT_SECTION_ALIGNMENT;
+                s->align = -1;

                 xstrncpy(s->segname, sm->segname);
                 xstrncpy(s->sectname, sm->sectname);
@@ -579,7 +579,8 @@
                         }

                         if ((-1 != originalIndex)
-                            && (s->align != newAlignment)) {
+                            && (s->align != newAlignment)
+                           && (s->align != -1)) {
                             error(ERR_PANIC,
                                   "section \"%s\" has already been specified "
                                       "with alignment %d, conflicts with new "
@@ -889,6 +890,8 @@
            fwritelong(offset, machofp);
            /* Write out section alignment, as a power of two.
               e.g. 32-bit word alignment would be 2 (2^^2 = 4).  */
+           if (s->align == -1)
+               s->align = DEFAULT_SECTION_ALIGNMENT;
            fwritelong(s->align, machofp);
            /* To be compatible with cctools as we emit
               a zero reloff if we have no relocations.  */
@@ -978,11 +981,10 @@
               offset which we already have. The linker takes care
               of the rest of the address.  */
            if (!r->ext) {
-               /* add sizes of previous sections to current offset */
-               for (s2 = sects, fi = 1;
-                    s2 != NULL && fi < r->snum; s2 = s2->next, fi++)
-                   if ((s2->flags & SECTION_TYPE) != S_ZEROFILL)
-                       l += s2->size;
+           /* add sizes of previous sections to current offset */
+           for (s2 = sects, fi = 1;
+                s2 != NULL && fi < r->snum; s2 = s2->next, fi++)
+               l += s2->size;
            }

            /* write new offset back */
@@ -1088,6 +1090,7 @@
                sym = undefsyms[i];
                if (sym->initial_snum == r->snum) {
                    r->snum = sym->snum;
+                   break;
                }
            }
        }
@@ -1257,14 +1260,14 @@
     raa_free(extsyms);

     if (syms) {
-       while (syms->next) {
-           sym = syms;
-           syms = syms->next;
+    while (syms->next) {
+       sym = syms;
+       syms = syms->next;

-           nasm_free (sym);
-       }
+       nasm_free (sym);
     }
 }
+}

 /* Debugging routines.  */
 static void debug_reloc (struct reloc *r)
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Lord Nightmare
Rookie
Posts: 14
Joined: Fri Nov 26, 2004 7:50 pm
Location: PA, USA
Contact:

Post by Lord Nightmare »

Was the code even SUBMITTED to official NASM yet?
I hope so...

Lord Nightmare
"When life gives you zombies... *CHA-CHIK* ...you make zombie-ade!"
BRPXQZME
Hazed
Posts: 54
Joined: Tue May 30, 2006 3:47 am
Location: Centreville, VA
Contact:

Post by BRPXQZME »

Don't think it has been, but mach-o is only useful for like, what? NeXT and OS X for the most part. The patches are in the nasm included with Xcode 2.4, so if you're developing for OS X you should upgrade anyway.
Lord Nightmare
Rookie
Posts: 14
Joined: Fri Nov 26, 2004 7:50 pm
Location: PA, USA
Contact:

Post by Lord Nightmare »

That doesn't really matter, its a bug nonetheless, and should be fixed.

Lord Nightmare
"When life gives you zombies... *CHA-CHIK* ...you make zombie-ade!"
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

BRPXQZME wrote:Don't think it has been, but mach-o is only useful for like, what? NeXT and OS X for the most part. The patches are in the nasm included with Xcode 2.4, so if you're developing for OS X you should upgrade anyway.
So that means we shouldn't be allowed to cross compile? And regardless it must be patched in the NASM tree.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
ZPedro
New Member
Posts: 4
Joined: Sat Jul 22, 2006 5:30 pm
Location: France

Post by ZPedro »

I agree that this should be fixed anyway (hey, who knows, perhaps some Linux or GNU hacker will come up with a GNU/Linux setup that uses Mach-O for executables instead of ELF, after all GNU/LinuxLinux used a.out initially...), but let me warn you that targeting the Mac by cross-compiling isn't easy. CodeWarrior on Windows used to make this possible (but only for PowerPC, and anyway now the Mac target of CW is dead), and I think some open-source solutions have been developed as well for ppc, but I don't know whether anyone succeeded yet for Darwin-i386. Googling turns up nothing, or no-success-yet such as this one. The source code of Apple's compiler toolchain is available as "Apple Public Source" (gcc, ld, and all the stuff) but it is not easy to compile on other platforms since it's not their goal (FSF gcc and as could, but there's still ld).

As for the environment, I don't know whether you would need the OSX 10.4u SDK (which contains stub libraries for both ppc and Intel), perhaps the SDL developer package for Mac would suffice.
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

ZPedro wrote:but let me warn you that targeting the Mac by cross-compiling isn't easy.
I fully disagree. Once I patched NASM, I was able to cross compile x86 assembly without difficulty.

The only issues is getting a GCC to output Mach-O objects. However I already have a cross compiler for PPC Linux. Meaning C is problematic at the moment. All one needs to obtain is the GCC which outputs Mach-O, and have a couple of lib files copied and I can cross compile ZSNES for OSX.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
ZPedro
New Member
Posts: 4
Joined: Sat Jul 22, 2006 5:30 pm
Location: France

Post by ZPedro »

Sorry, I should have been clearer: having a full cross-compiling toolchain that can target Mac OS X may not be easy to set up. I know that nasm has no problem cross-assembling, it has always been designed that way. It's everything else that may be a problem.
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

Yeah, but all we really need for ZSNES is GCC, G++, and binutils targeted for cross.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Post Reply