Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
1
answers
51
views
Why does assembler called from script not create a certain file when run from crontab?
I'm using [this script](https://hg.pushbx.org/ecm/wwwecm.scr/file/dfb37b7cdb68/update-dl-wwwecm) to build and package some applications I developed. Full content of the script is listed at the end. It is called by this crontab entry: `50 23 * * * nice $HOME/update-dl-wwwecm $HOME | tee -a $HOME/buil...
I'm using [this script](https://hg.pushbx.org/ecm/wwwecm.scr/file/dfb37b7cdb68/update-dl-wwwecm) to build and package some applications I developed. Full content of the script is listed at the end.
It is called by this crontab entry:
50 23 * * * nice $HOME/update-dl-wwwecm $HOME | tee -a $HOME/build-dl-wwwecm/log
For debugging I copied the script to a test directory ~/test/20211101/t/
and edited it slightly. (As in removing some of the packages that are hardcoded at the end of the script.) I also manually mkdir build-dl-wwwecm
and mkdir webrepos
in this test directory and hg clone
to get the following repos into the webrepos
subdirectory:
1. [lmacros macro collection](https://hg.pushbx.org/ecm/lmacros/) (This one is required to build any of the others. And it should be listed as the first repo to update.)
2. [lClock application](https://hg.pushbx.org/ecm/lclock/)
3. [KEEPHOOK utility](https://hg.pushbx.org/ecm/keephook/)
4. [SHUFHOOK utility](https://hg.pushbx.org/ecm/shufhook/)
Next I added an "every minute" line to my crontab like this: * * * * * nice $HOME/test/20211101/t/update-dl-wwwecm $HOME/test/20211101/t | tee -a $HOME/test/20211101/t/build-dl-wwwecm/log
The update script checks for incoming commits from the repos in the webrepos subdirectory. It then pulls the new commits and for every mak.sh
script file found in the build directory tree it changes into that file's directory and runs that file. This is [the full mak.sh
for KEEPHOOK](https://hg.pushbx.org/ecm/keephook/file/c3ead749bea9/mak.sh) :
#! /bin/bash
nasm -I ../lmacros/ -f bin transien.asm -l keephook.lst -o keephook.com "$@"
Now what I observe is if I call the update script myself logged in as my user (via ssh, running bash within screen, connected to the server with the ConnectBot app), then everything works as expected. The commands go like this: hg -R build-dl-wwwecm/keephook strip tip
(so the update script will find a new commit to pull) then ./update-dl-wwwecm "$PWD"
(to actually do the update, with the parameter for BASE specified as the test directory).
However, if the same script is called from the crontab then one thing is different: NASM appears to delete and then not create the output file keephook.com
- although it does create a keephook.lst
listing file that appears to be complete. No error or warning is found in the log file. All other applications are built fine.
Why is that and how to fix it?
---
Here's the full update script:
#! /bin/bash
# Usage of the works is permitted provided that this
# instrument is retained with the works, so that any entity
# that uses the works is notified of this instrument.
#
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
BASE="$1"
if [[ -z "$BASE" ]]
then
echo "Error: No base specified." >&2
exit 1
fi
SDIR="$BASE"/webrepos
[[ -n "$2" ]] && BASE="$2"
BDIR="$BASE"/build-dl-wwwecm
TDIR="$BASE"/wwwecm/download
ODIR="$BASE"/wwwecm/download/old
[[ ! -d "$BDIR" ]] && mkdir -p "$BDIR"
[[ ! -d "$TDIR" ]] && mkdir -p "$TDIR"
[[ ! -d "$ODIR" ]] && mkdir -p "$ODIR"
function update() {
# $1 = path below BDIR
# $2 = "-r" if there is a branch
# $3 = branch name if there is a branch
if [[ ! -d "$BDIR"/"$1" ]]
then
hg init "$BDIR"/"$1"
fi
cd "$BDIR"/"$1"
if var="$(hg incoming "$SDIR"/"$1" $2 $3)"; then
echo "$var"
hg pull "$SDIR"/"$1" $2 $3 && hg up $3
find . -name mak.sh -print0 | \
ONE="$1" xargs -r0 bash -c \
'for file; do echo === "$ONE"/"$file"; (cd "${file%/*}"; "./${file##*/}"); done' scriptlet
if [[ -f "$TDIR"/"$1".zip ]]
then
[[ ! -d "$ODIR"/"$1" ]] && mkdir -p "$ODIR"/"$1"
datestamp="$(date -r "$TDIR"/"$1".zip +%Y%m%d)"
echo === mv --backup=numbered "$TDIR"/"$1".zip "$ODIR"/"$1"/"$datestamp".zip
mv --backup=numbered "$TDIR"/"$1".zip "$ODIR"/"$1"/"$datestamp".zip
fi
echo === zipping "$1"
7za a -mm=deflate -mx=9 -tzip "$TDIR"/"$1".zip *
fi
}
update lmacros
update keephook
update shufhook
update rxansi
update lclock
update seekext
update tsr
update fdapm
update renumber
touch "$BDIR"/lastrun
ecm
(143 rep)
Nov 1, 2021, 08:33 PM
2
votes
1
answers
2715
views
-bash: ./ex1: cannot execute binary file: Exec format error (on Ubuntu installed through Windows 10 app store, 64 bit)
I am trying to start out with some assembly but I run into this error from the outset. Here are the details: I've written the file myself (following a video) so its not some import: global _start _start: mov eax, 1 mov ebx, 42 int 0x80 Pretty basic. I assemble and link it ( nasm -f elf32 ex1.asm -o...
I am trying to start out with some assembly but I run into this error from the outset. Here are the details: I've written the file myself (following a video) so its not some import:
global _start
_start:
mov eax, 1
mov ebx, 42
int 0x80
Pretty basic. I assemble and link it (
nasm -f elf32 ex1.asm -o ex1.o
followed by
ld -m elf_i386 ex1.o -o ex1
checking the exit status at each stage with echo $?).
It assembles and links fine. File gives:
ex1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped
My processor is a 64-bit AMD Ryzen 3 2200G, and my Win10 host and Ubuntu are also 64 bit (from what I've read running a 32 bit binary in a 64 bit environment is fine, right?). I have read many posts and they either discuss trying to run 64 on a 32, or corrupt imports or arch incompatibility (e.g. assembled for ARM) or more complex issues. This here is quite straight forward and for all intents and purposes it should simply run. However when I try it I get
-bash: ./ex1: cannot execute binary file: Exec format error
This is on Ubuntu installed through Windows 10 app store, 64 bit.
Any suggestions?
x iLeon
(39 rep)
May 31, 2020, 12:10 PM
• Last activity: May 23, 2021, 01:03 AM
0
votes
0
answers
135
views
How to disassemble floppy disk?
I want to disassemble floppy disk and assemble it again with `nasm -f bin` command. For example, I want to disassemble MS-DOS `.img` files and assemble it again with `nasm -f bin` command. I tried to use `ndisasm` command: ndisasm -b 16 File.img
I want to disassemble floppy disk and assemble it again with
nasm -f bin
command. For example, I want to disassemble MS-DOS .img
files and assemble it again with nasm -f bin
command.
I tried to use ndisasm
command:
ndisasm -b 16 File.img
sbh
(71 rep)
Feb 26, 2021, 03:10 PM
8
votes
1
answers
6045
views
What are difference between the ELF symbol visibility levels?
The [NASM docs on *"`elf` Extensions to the GLOBAL Directive"* say,](https://www.nasm.us/doc/nasmdoc7.html) > Optionally, you can control the ELF visibility of the symbol. Just add one of the visibility keywords: `default`, `internal`, `hidden`, or `protected`. The default is `default` of course. Wh...
The [NASM docs on *"
elf
Extensions to the GLOBAL Directive"* say,](https://www.nasm.us/doc/nasmdoc7.html)
> Optionally, you can control the ELF visibility of the symbol. Just add one of the visibility keywords: default
, internal
, hidden
, or protected
. The default is default
of course.
Where are these defined? and how does ld
use them? I see [access levels mentioned frequently in C++ which include *protected*, *public*, and *private*](https://en.cppreference.com/w/cpp/language/access) , but I don't know if this is what ELF is referencing?
My use-case is C and Assembly so if you can make this relevant to those two languages and the linker, extra points.
Evan Carroll
(34663 rep)
Oct 1, 2018, 11:47 PM
• Last activity: Oct 2, 2018, 02:41 PM
0
votes
1
answers
2280
views
Running a custom-compiled executable returns "No such file or directory"
I have an executable but when I run it I get *"No such file or directory"* $ chmod a+x bin $ file bin bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld64.so.1, not stripped $ ./bin bash: ./bin: No such file or directory Notice that this executable is i...
I have an executable but when I run it I get *"No such file or directory"*
$ chmod a+x bin
$ file bin
bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld64.so.1, not stripped
$ ./bin
bash: ./bin: No such file or directory
Notice that this executable is in fact ELF 64-bit, as is the operating system.
Evan Carroll
(34663 rep)
Oct 1, 2018, 11:04 PM
• Last activity: Oct 1, 2018, 11:05 PM
2
votes
1
answers
5707
views
Compile shared library from asm code with current sources
I just did some basic functions in asm that I compile in a shared library. Like : BITS 64 global foo section .text foo: mov rax, 1 ret I compiled with : nasm -f elf64 foo.S -o foo.o && gcc -shared foo.o -o libfoo.so I have a main of test : #include int foo(); int main() { printf("%d\n", foo()); retu...
I just did some basic functions in asm that I compile in a shared library.
Like :
BITS 64
global foo
section .text
foo:
mov rax, 1
ret
I compiled with :
nasm -f elf64 foo.S -o foo.o && gcc -shared foo.o -o libfoo.so
I have a main of test :
#include
int foo();
int main()
{
printf("%d\n", foo());
return (0);
}
If I compiled it with the foo.o directly, everything works well. But if I compiled like this :
gcc main.c -L. -lfoo
I would get this error :
/usr/.../bin/ld: warning: type and size of dynamic symbol `foo' are not defined
I thought it was because the prototype is not declared, but I recompiled foo.o with a lib.h file containing the prototype, and the same problem occurs.
Is that I must complete another section of the elf file?
Thank you.
OOM
(133 rep)
Mar 23, 2016, 04:46 PM
• Last activity: Oct 1, 2018, 09:29 PM
Showing page 1 of 6 total questions