Nasm bug workaround

buggy NASM doesn’t relocate symbols properly. I don’t really know why
SDL works with the current code — it must be pure luck — because when
I run it in a slightly different context I get a segfault in _Hermes_X86_CPU.

And when looking at the NASM-generated code it’s quite obvious what’s going
on: NASM generates relocation records for the cpu_flags variable all right,
but they are relative the .text section, not .data, so the runtime linker
does the wrong thing

In this case that variable isn’t needed (patch follows), but in general
I would like to get rid of NASM and Hermes (not necessarily in that order)

Index: x86_main.asm===================================================================
RCS file: /home/slouken/libsdl.org/cvs/SDL12/src/hermes/x86_main.asm,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 x86_main.asm
— x86_main.asm 2001/04/26 16:45:45 1.1.1.1
+++ x86_main.asm 2001/10/04 09:20:02
@@ -17,11 +17,6 @@
GLOBAL _Hermes_X86_CPU

-SECTION .data

-cpu_flags dd 0

SECTION .text

;; _ConvertX86:
@@ -109,17 +104,12 @@
pop eax
xor eax,ecx
je .L1

  • pusha
  • push ebx ; ebx is callee-saves
    mov eax,1
    cpuid
  • mov [cpu_flags],edx
  • popa
  • mov eax,[cpu_flags]
  • pop ebx
  • mov eax,edx

.L1:
ret

buggy NASM doesn’t relocate symbols properly. I don’t really know why
SDL works with the current code — it must be pure luck — because
when
I run it in a slightly different context I get a segfault in
_Hermes_X86_CPU.
BTW could you advice me an ASM book ?

Lloyd Dupont wrote:

BTW could you advice me an ASM book ?

Yes.

BTW could you advice me an ASM book ?

I like “Linux Assembly Language Programming” from Prentice Hall by Bob
Neveln. It’s Linux centered, which may or may not be a good thing
depending on whether you use Linux or not. It uses NASM.

-MarkOn Thu, 4 Oct 2001, Lloyd Dupont wrote:


Mark K. Kim
http://www.cbreak.org/mark/
PGP key available upon request.

BTW could you advice me an ASM book ?

I like “Linux Assembly Language Programming” from Prentice Hall by Bob
Neveln. It’s Linux centered, which may or may not be a good thing
depending on whether you use Linux or not. It uses NASM.

cool…
mmhh… i used to work on windows, is it a real problem when writing
library ?
i used to write ASM long time ago and it seems to me that OS
idiosyncrasies are thin, no ?

I wrote:

buggy NASM doesn’t relocate symbols properly. I don’t really know why
SDL works with the current code — it must be pure luck — because when
I run it in a slightly different context I get a segfault in _Hermes_X86_CPU.

OK, I’ve done some more research. This is a NASM bug that seems to be
fixed in 0.98.08 (maybe earlier), but it’s still there in 0.98 which
came preinstalled on this redhat 7.1 box. The bug affects other things
as well so my patch was necessary but not sufficient. Better to note
the bug and require a recent NASM version in the configure script