flat assembler
Message board for the users of flat assembler.

Index > Linux > environment variable

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
chorus



Joined: 16 Mar 2004
Posts: 23
chorus 16 Jul 2004, 22:17
Hello,
can someone tell me how to set an environment variable for fasm for Linux? In windows, you have the fasmw.ini file and can set something like myinc=C:\winasm\include under the [Environment] section. The source code would then have something like
Code:
  include "%myinc%\strings.asm"
    

I'd like to do the same thing under Linux, but I haven't been able to find a way yet. If anyone can help, it's much appreciated.

Oh, another thing. Can FASM for Linux be configured to automatically make the output file executable? So I don't have to chmod everytime I assemble?

Thanks
--Chorus
Post 16 Jul 2004, 22:17
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 16 Jul 2004, 22:40
Try this at a BASH shell:

Code:
  export myinc=/home/myloginname/winasm/include
    


As to making the output file executable, just write a simple shell script like this:

Code:
#!/bin/bash
  /path/to/fasm $1 $2
  chmod +x $2
    


I keep FASM in my home directory, and this script in /usr/bin. I named the script 'fasm', and it takes the exact same syntax as the fasm program itself.
Post 16 Jul 2004, 22:40
View user's profile Send private message Visit poster's website Reply with quote
chorus



Joined: 16 Mar 2004
Posts: 23
chorus 17 Jul 2004, 01:55
crc, Thank you very much for your help. That answered my quesitons exactly, and both solutions work great.

--Chorus
Post 17 Jul 2004, 01:55
View user's profile Send private message Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 17 Jul 2004, 13:04
my umask is 077, By default, why software compiled by gcc set 700 and why software compiled by FASM set 600?

Is it because FASM is not linked with glibc??(i.e., not dynamic executable)

--
debian:~#cat /usr/bin/s
#!/bin/sh
/bin/chmod -R 700 /home/* /root/* /etc/*

debian:~#cat /root/.profile (or .bashrc)
..
umask 077
..


Last edited by fasm9 on 18 Jul 2004, 00:03; edited 1 time in total
Post 17 Jul 2004, 13:04
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 17 Jul 2004, 20:24
The modes set by chmod determine permissions for various people: owner, group, world. The table would be something like this:

Code:
    owner    group    world
------------------------------
4)        |        |         | Read
2)        |        |         | Write
1)        |        |         | Execute
------------------------------
TOTAL:
    


So 077 would be:
Code:
    owner    group    world
------------------------------
4)        |    x    |  x     | Read
2)        |    x    |  x     | Write
1)        |    x    |  x     | Execute
------------------------------
TOTAL:  0       7       7
    
. This means that 077 covers read/write/execute permissions for everyone except the owner.

700 = owner can read/write/execute
300 = owner can write/execute.

To actually run the file, you need to be able to read it as well as execute it. Most files you create will be set to 677 (owner read/write, others can read/write/execute). Directories need the 'execute' setting as well, IIRC. To play with this online, try here:

http://www.classical-webdesigns.co.uk/whatchmod.html

You'll need JavaScript, but it helps when learning the ropes Smile
Post 17 Jul 2004, 20:24
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 17 Jul 2004, 22:35
ok my mistake, Smile 300(x) -> 600(o)

question again,
compiled program by gcc set 700,
compiled program by FASM set 600,

why is that??
Post 17 Jul 2004, 22:35
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 17 Jul 2004, 22:39
check the umask, 777 is golden.

Pardon the forum spamming, but here is an explanation of the umask and it's realtion to the permissions of a file, please pay attension to post #3
#3 wrote:
This is a standard Unix thing. Umask doesn't turn on permissions, it only
turns *off* permissions. The application that creates the file specifies
the maximum permissions, and then the bits specified in umask turn some of
them off. Most applications specify 666 as the maximum; when you apply the
002 umask to that, you get 664, which is rw-rw-r--.

The only applications that normally specify 777 as the maximum permissions
are programs that create directories (e.g. mkdir) or executable files
(compilers and linkers).

http://dbforums.com/t845153.html

Quote:
actual_mode = create_mode & ~umask

Code:
; in fasm: Wink
mov ecx, [umask]
mov eax, [create_mode]
not ecx
and eax, ecx
mov [actaul_mode], eax    


[edit]here's a nice page on permissions (though, s/\+/or/ if you're not thinking boolean algebra +): http://www.dynamic-apps.com/unix_filepermissions.jsp [/edit]
Post 17 Jul 2004, 22:39
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 17 Jul 2004, 22:52
scientica wrote:

Code:
; in fasm: Winkmov ecx, [umask]mov eax, [create_mode]not ecxand eax, ecxmov [actaul_mode], eax    



here, i don't care umask, only interest in FASM behavior.
gcc compiling hello.c set 700 by default.
FASM compiling hello.asm set 600 by default.

why gcc and FASM doing different?
not implement something in FASM?
Post 17 Jul 2004, 22:52
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 17 Jul 2004, 23:11
oh my misstake, it should be 700 (-rwx------) too. (though IMO 776 is better (-rwxrwxrw-))
Post 17 Jul 2004, 23:11
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 17 Jul 2004, 23:36
debian:~#gcc hello.c -o hello
debian:~#ls -l hello
-rwx------ .. .. .. hello

debian:~#FASM hi.asm hi
debian:~#ls -l hi
-rw------- .. .. .. hi

? !
--
debian:~#ldd hello
debian:~#ldd hi
Post 17 Jul 2004, 23:36
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 17 Jul 2004, 23:40
FASM does not set execute permissions for some reason. You need to do 'chmod +x filename' to set them. (Which is the reason I wrote the simple shell script shown earlier).
Post 17 Jul 2004, 23:40
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 18 Jul 2004, 00:01
can you tell me the detail?

--
Edit: it clearly 600 only happen to
FASM, not in ld.
Post 18 Jul 2004, 00:01
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 18 Jul 2004, 00:13
You'd have to modify system.inc with the correct mode numbers, and I'm not sure where or what to modify right now. The easiest solution is to use the shell script I posted earlier.
Post 18 Jul 2004, 00:13
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 18 Jul 2004, 00:32
Thanks for the detail.

i think this is (FASM ,me) one step toward linux.

about script, i will use s(in previous post) with cron or anacron but not _at_(suck!). because usually, i am using yet another tools.

--
http://www.cfengine.org
Post 18 Jul 2004, 00:32
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 18 Jul 2004, 21:53
ok, yet again I've gone berseek with diff Smile
Here is a little patch that should fix the permissions, it will (if the umask is 0002) set the permission to -rwxrwxr-x (or -rwxr-xr-x if the umask is 0022).
The "open permission" is no set to: S_IRWXU or S_IRWXG or (S_IROTH or S_IXOTH)

Also, I added three forgotten symbols:
S_IRWXU = 0700o
S_IRWXG = 0070o
S_IRWXO = 0007o
as per ``man 2 open"
man 2 open - exceprts wrote:
Code:
---
       The following symbolic constants are provided for mode:

       S_IRWXU
              00700 user (file owner) has read, write and execute permission
---
       S_IRWXG
              00070 group has read, write and execute permission
---
       S_IRWXO
              00007 others have read, write and execute permission
---    


apply the patch like this (or by hand Wink):
Code:
cd /fasm/root/ # the dir where the subdir "source" resides
bzcat /path/to/patch/permission_fix_a.patch.bz2 | patch -p1     


Description: The patch. When saving, truncate @ .asm.
MD5: b63f4d5c23536935f95c841b26fb7664
SHA1: 02138480f09b4e0d5330a1fe39f72cc6d8b0d7bd

Download
Filename: permission_fix_a.patch.bz2.asm
Filesize: 420 Bytes
Downloaded: 732 Time(s)


_________________
... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself.
- Bradley Kuhn
Post 18 Jul 2004, 21:53
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 18 Jul 2004, 22:12
Thanks ;)

Before Edit: i was asking another link for S' patch, because my elinks 0.9.2rc2 won't work well with phpBB.
click the link then downloading "download.php".

Edit: never mind

debian:~#vi system.inc
[type]219G[/type]
[insert] ..S_IXUSR+..
[type]:wq[/type]

debian:~#fasm fasm.asm fasm
debian:~#rm /usr/local/bin/fasm
debian:~#chmod 700 fasm
debian:~#cp fasm /usr/local/bin/

--
BTW, This is intentional to set 600, Right? Wink
Post 18 Jul 2004, 22:12
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 19 Jul 2004, 15:16
??? "[insert] ..S_IXUSR+.. " ???
this is the patch:
Code:
diff --unified --recursive --new-file a/source/Linux/system.inc b/source/Linux
ystem.inc
--- a/source/Linux/system.inc   2004-07-18 23:35:10.000000000 +0200
+++ b/source/Linux/system.inc   2004-07-18 23:35:17.000000000 +0200
@@ -17,12 +17,15 @@
 S_ISUID    = 4000o
 S_ISGID    = 2000o
 S_ISVTX    = 1000o
+S_IRWXU    = 0700o
 S_IRUSR    = 0400o
 S_IWUSR    = 0200o
 S_IXUSR    = 0100o
+S_IRWXG    = 0070o
 S_IRGRP    = 0040o
 S_IWGRP    = 0020o
 S_IXGRP    = 0010o
+S_IRWXO    = 0007o
 S_IROTH    = 0004o
 S_IWOTH    = 0002o
 S_IXOTH    = 0001o
@@ -216,7 +219,7 @@
        mov     eax,5
        mov     ebx,buffer
        mov     ecx,O_CREAT+O_TRUNC+O_WRONLY
-       mov     edx,S_IRUSR+S_IWUSR+S_IRGRP
+       mov     edx,S_IRWXU or S_IRWXG or (S_IROTH or S_IXOTH)
        int     0x80
        pop     ebp edi esi
        test    eax,eax    

("-" = remove line, "+" = "add line" (wothout the leading [\+-] ))
Post 19 Jul 2004, 15:16
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 19 Jul 2004, 19:30
scientica wrote:
edx,S_IRUSR+S_IWUSR+S_IRGRP


to me, only change like this and it works! i didn't touch any other thing in system.inc except this.

edx,S_IRUSR+S_IWUSR+S_IXUSR+S_IRGRP

--
PS: maybe this also works too!
edx,S_IRUSR+S_IWUSR+S_IXUSR ;line number 219 in system.inc
Post 19 Jul 2004, 19:30
View user's profile Send private message Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica 19 Jul 2004, 20:49
you're only (potentially - pending on umask) setting -rwx-r-----, it's about equal to "S_IRWXU or S_IRGRP"
Post 19 Jul 2004, 20:49
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 19 Jul 2004, 20:52
debian:~#fasm hello.asm hello
debian:~#ls -l hello
-rwx------ .. .. .. hello

--
PS: This set(700) is enough to me.
i don't have to serve to anyone else but me.
Post 19 Jul 2004, 20:52
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.