Hi all I wondering how to use constants , defined in /usr/include/asm/*.h files in gas.Documentation says, if i has an *.S file, i can use c/c++ preprocessor in gas.I has following lines in file demonize.S: Код (Text): #include <asm/unistd.h> #include <asm/fcntl.h> . . . movl $__NR_open,%eax movl $O_RDWR,%ebx orl $O_CREAT,%ebx orl $O_EXCL,%ebx . . Can't compile it: errors from ld: Код (Text): as -gstabs -o demonize.o demonize.S gcc -o cvd main.o setopts.o demonize.o -g demonize.o(.text+0x2b):demonize.S:42: undefined reference to `__NR_open' demonize.o(.text+0x30):demonize.S:43: undefined reference to `O_RDWR' demonize.o(.text+0x36):demonize.S:44: undefined reference to `O_CREAT' demonize.o(.text+0x3c):demonize.S:45: undefined reference to `O_EXCL' collect2: ld returned 1 exit status make: *** [cvd] Ошибка 1 My Makefile: Код (Text): all: cvd cvd: main.o setopts.o demonize.o gcc -o cvd main.o setopts.o demonize.o -g main.o: main.S as -gstabs -o main.o main.S setopts.o: setopts.S as -gstabs -o setopts.o setopts.S demonize.o: demonize.S as -gstabs -o demonize.o demonize.S Thanks
nopnopnop gas treats all unknown (undefined) symbols as externals. You need to ensure thouse constants are actually defined somewhere (i.e. in the *.h files). But it's easier to define 'em directly in your source: Код (Text): O_RDWR = 2 O_CREAT = 00400 O_EXCL = 02000 __NR_open = 5
Hi Quantum This is the problem ,for which i want to find solution Thouse constants NOT defined! They are defined in files <asm/unistd.h> and <asm/fcntl.h>, but i can't refer to them in my assembly code. For a while i redefined constats by my self in .data section: Код (Text): .equ SYS_open, 5 .equ SYS_write, 4 .equ SYS_read, 3 .equ SYS_getpid, 20 .equ SYS_chdir, 12 .equ O_WRONLY, 01 .equ O_RDWR, 02 .equ O_CREAT, 0100 .equ O_EXCL, 0200 .equ O_RDONLY, 00 .equ O_APPEND, 02000 But it's definitelly not prefferred way! I took a look at sources in "linux-2.6.17/arch/i386/kernel" *.S files... They DO have use of cpp(c/c++ preprocessor: lines #include...),but i can't fugure out how to use this ficher. May be i have an error in my Makefile, may be i omiited something in the sintax, may be something else... Don't you thing it will be much more convenient(and portable: O_CREAT in my system is 200) to use include files provided by the distribution? And, finally, those files, /usr/include/asm/*.h - what is good for ?
nopnopnop The # character is interpreted as the start of a single-line comment, so #include won't work in gas. But there's .include keyword available. Not of much help, because the #define's would be treated as comments too. Have you read the man? (here it is: http://www.gnu.org/software/binutils/manual/gas-2.9.1/html_mono/as.html) Maybe, it's possible to tweak gcc (-E option performs preprocessing only) to compile *.S files.
HI 1. -E option not recognized by as ( on my box running FC4 ) 2. # character in *.S files passed to cpp, therefor it could be used as comment 3. .include derective works fine, but in defferent case. It passes source file to gasp preprosesor( accordig to documentation - i can't find such a program ) It's impossible to use this derective to use system-defined constatnts. I tryed to compile my project like this: gcc -o cvd main.S setopts.S demonize.S Dosn't work, but it was close. There was couple of struct definitions in those headers files, thats why compilation failed. But again...i now it must work! Here pice of code from "linux/boot/head.S" Код (Text): .text #include <linux/linkage.h> #include <asm/segment.h> #include <asm/page.h> .globl startup_32 startup_32: cld cli movl $(__BOOT_DS),%eax movl %eax,%ds movl %eax,%es movl %eax,%fs movl %eax,%gs When i do something like this ( movl $__NR_open,%eax ) it dosn't work...
nopnopnop Here an example on use of structures In header file: Код (Text): struct KSome # ... fld Entry, QWORD * KOBJ_TABLE_SIZE # ... ends KSome struct ListEntry fld Flink, PVOID fld Blink, PVOID ends ListEntry and in asm file: Код (Text): movl $_kFoo + f.Entry, %edi 0: movl %edi, f.Flink(%edi) // ListHead->Flink = ListHead->Blink = ListHead; movl %edi, f.Blink(%edi)
My question was about interaction between gas and preprocessor, not about structs.Take a look at the first post: do you see any error in my code ? Whi it dosn't work... P.S. where did you find description of struct .. ends in gas? Can i have a link?
nopnopnop gcc preprocesses *.S files (capital S) instead of passing them directly to gas. The -E option was there since version 3.1.1. Maybe, you need to upgrade your gcc. Iceberg Maybe you call gcc instead of gas? #include/#define usage isn't documented for gas, AFAIK.