Tiny Core Linux

Tiny Core Base => TCB Bugs => Topic started by: webb on August 11, 2019, 02:56:35 AM

Title: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: webb on August 11, 2019, 02:56:35 AM
Code: (bash) [Select]
webb@box ~ filetool.sh -b
Backing up files to /mnt/vda1/tce/mydata.tgz/
Done.
caused by
Code: (bash) [Select]
echo -n on line 173 of filetool.sh combined with a following line outputting a slash, maybe
Code: (bash) [Select]
sudo /bin/tar -C /
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on August 11, 2019, 06:55:51 AM
Hi webb
The extra  /  character is coming from the  rotdash (rotating dash)  command. The  rotdash  command writes the following sequence:
Code: [Select]
/ Backspace
- Backspace
\ Backspace
| Backspace
So depending on how long your backup takes, any one of those characters could be left behind. The attached patch file fixes it
by including a leading  space  character in the next 2  echo  commands. That will overwrite the character left by  rotdash.


    [EDIT]: Moved attachment to the next post.  Rich
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on August 11, 2019, 07:44:50 AM
Hi Juanito
The attached patch file does the following:
1. Adds a trailing space to the  "Backing up files to $MOUNTPOINT/$FULLPATH/${MYDATA}.tgz"  message so that  rotdash  does not
   print right next to the trailing  z. This also provides a space if the  "encrypting .. "  message gets printed which itself will overwrite
   anything that  rotdash  leaves behind.
2. Adds a leading space to the  "\nDone."  message to overwrite anything that  rotdash  leaves behind.
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on August 11, 2019, 08:59:18 PM
Hi Juanito
If there's any interest, I have a patch for  rotdash  that leaves the screen as it found it when it exits. Compiling under TC4 and
using  sstrip  increases the executables size from 1688 bytes to 1708 bytes. In TC10 I can't get the size under 12324 bytes.

The addition line of code is shown here with a comment and the diff is attached below:
Code: [Select]
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv){

if (argc != 2) return 1;

const char arr[] = { '/', '-', '\\', '|' };
unsigned int i = 0;
chdir("/proc");

while (access(argv[1],F_OK) == 0) {
printf("%c\b",arr[i]);
fflush(stdout);
i++;
i %= 4;
usleep(100000);
}

// This clears from the cursor to the end of the line leaving
// the screen and cursor as they were when the program started.
printf("\033[K");
return 0;
}

The source code I used came from here:
http://distro.ibiblio.org/tinycorelinux/4.x/x86/release/src/3.x/rotdash.c
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Greg Erskine on August 11, 2019, 11:03:16 PM
I often output rotdash into a <textarea> on a web page via filetool.sh. The backspace does not work now but it isn't a big problem.

If you add an escape character into the output it would be really bad for displaying via a web page.

I already have replacement rotdash code ready if it is decided you decide to procede.

Example:

Code: [Select]
[ INFO ] Backing up files to /mnt/mmcblk0p2/tce/mydata.tgz/-\|/ Done.
[ OK ] Backup successful.
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: curaga on August 11, 2019, 11:55:11 PM
Let's go with the filetool patch, given Greg's web use.
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Juanito on August 12, 2019, 12:34:44 AM
tinycore git updated
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on August 12, 2019, 08:03:46 AM
Hi Greg Erskine
I often output rotdash into a <textarea> on a web page via filetool.sh. The backspace does not work now but it isn't a big problem.

If you add an escape character into the output it would be really bad for displaying via a web page. ...
I had no idea anyone used this for a web page. I suppose I could have printed a  space  followed by a  backspace:
Code: [Select]
printf(" \b");Since the  backspace  moves the cursor back 1 position the trailing  space  would simply get overwritten if more text were added.
If the next character was a  newline,  it would print the trailing space which wouldn't be visible anyway. This was the mechanism
that made the trailing slash visible.

Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: jazzbiker on August 12, 2019, 08:30:41 AM
Compiling under TC4 and using  sstrip  increases the executables size from 1688 bytes to 1708 bytes. In TC10 I can't get the size under 12324 bytes.

Hi, Rich!
Sorry for offtopic. Can you kindly explain to the newbie such a size difference?
Not a first mentioning of TC4 at the forum as the kind of milestone. What have changed later? Some kernel bloat?
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on August 12, 2019, 08:56:15 AM
Hi jazzbiker
... Can you kindly explain to the newbie such a size difference? ...
I honestly don't know why the executable is so much larger. My guess is the current compiler has some "enhancements" not present
in the TC4 version that add some overhead. There appear to be some differences in how they were built.

TC4:
Code: [Select]
tc@box:~/rotdash$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/tmp/tcloop/gcc/usr/local/bin/../lib/gcc/i686-pc-linux-gnu/4.6.1/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.6.1/configure --prefix=/usr/local --libexecdir=/usr/local/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++ --disable-multilib --disable-bootstrap --with-system-zlib --enable-frame-pointer
Thread model: posix
gcc version 4.6.1 (GCC)
tc@box:~/rotdash$

TC10:
Code: [Select]
tc@E310:~/rotdash$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/tmp/tcloop/gcc/usr/local/bin/../lib/gcc/i486-pc-linux-gnu/8.2.0/lto-wrapper
Target: i486-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local --enable-languages=c,c++ --disable-multilib --disable-bootstrap --disable-libmpx --with-system-zlib --libexecdir=/usr/local/lib --enable-frame-pointer --with-mpfr=/usr/local --with-gmp=/usr/local
Thread model: posix
gcc version 8.2.0 (GCC)
tc@E310:~/rotdash$
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: jazzbiker on August 12, 2019, 10:31:19 AM
My guess is the current compiler has some "enhancements" not present
in the TC4 version that add some overhead.

Thanks for Your answer, Rich.
My feeling is that sometimes tcc is the real alternative to gcc - for simple programs.
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: jazzbiker on August 13, 2019, 03:51:59 AM
Continuing off-topic:

Code: [Select]
tc@box:/tmp$ uname -a
Linux box 4.19.10-tinycore #1999 SMP Tue Dec 18 13:36:47 UTC 2018 i686 GNU/Linux
tc@box:/tmp$ wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/release/src/3.
x/rotdash.c
Connecting to distro.ibiblio.org (152.19.134.43:80)
rotdash.c            100% |********************************|   317  0:00:00 ETA
tc@box:/tmp$ tce-load -i tcc
tcc is already installed!
tc@box:/tmp$ tcc -v
tcc version 0.9.26 (i386 Linux)
tc@box:/tmp$ tcc -o rotdash rotdash.c
tc@box:/tmp$ ls -l rotdash*
-rwxr-xr-x    1 tc       staff         2816 Aug 13 13:49 rotdash
-rw-r--r--    1 tc       staff          317 Aug 13 13:48 rotdash.c
tc@box:/tmp$ tce-load -i sstrip
sstrip is already installed!
tc@box:/tmp$ sstrip rotdash
tc@box:/tmp$ ls -l rotdash*
-rwxr-xr-x    1 tc       staff         1312 Aug 13 13:49 rotdash
-rw-r--r--    1 tc       staff          317 Aug 13 13:48 rotdash.c
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on August 13, 2019, 11:14:56 PM
Hi jazzbiker
I honestly don't know why the executable is so much larger. My guess is the current compiler has some "enhancements" not present
in the TC4 version that add some overhead. ...
I don't know why it's happening, but I know what's happening. I looked through the stripped file and found 3 large blocks of zeros.
Each block was over 3500 bytes long.

... In TC10 I can't get the size under 12324 bytes. ...
Subtracting 3 times 3500 from 12324 leaves 1824 which suggests all the growth consists of zero padding.
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: jazzbiker on August 14, 2019, 12:41:34 AM

I don't know why it's happening, but I know what's happening. I looked through the stripped file and found 3 large blocks of zeros.
Each block was over 3500 bytes long.


Some initialized variables. They may be examined better before stripping, probably.
But tcc gives 1312 total size )
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: jazzbiker on August 14, 2019, 01:22:28 AM
Code: [Select]
tc@box:/tmp/rotdash$ nm  -n -S rotdash
         U access@@GLIBC_2.0
         U chdir@@GLIBC_2.0
         U fflush@@GLIBC_2.0
         w __gmon_start__
         U __libc_start_main@@GLIBC_2.0
         U printf@@GLIBC_2.0
         U usleep@@GLIBC_2.0
08049000 T _init
08049090 T _start
080490c0 00000004 T __x86.get_pc_thunk.bx
080490c4 t deregister_tm_clones
080490ec t register_tm_clones
08049122 t __do_global_dtors_aux
08049140 t frame_dummy
08049142 000000bb T main
080491fd 0000004f T __libc_csu_init
0804924c 00000001 T __libc_csu_fini
08049250 T _fini
0804a000 00000004 R _fp_hw
0804a004 00000004 R _IO_stdin_used
0804a014 r __FRAME_END__
0804bf04 t __frame_dummy_init_array_entry
0804bf04 t __init_array_start
0804bf08 t __do_global_dtors_aux_fini_array_entry
0804bf08 t __init_array_end
0804bf0c d _DYNAMIC
0804c000 d _GLOBAL_OFFSET_TABLE_
0804c024 D __data_start
0804c024 W data_start
0804c028 D __dso_handle
0804c02c B __bss_start
0804c02c D _edata
0804c02c 00000004 B stdout@@GLIBC_2.0
0804c02c D __TMC_END__
0804c030 00000001 b completed.6835
0804c034 B _end

After _fini in text section next symbol is _fp_hw in read-only section and it is aligned on xxx000.
Then _GLOBAL_OFFSET_TABLE_ is aligned the same way.

There may be some linker switches concerning section alignment, i guess.

Th hole between __FRAME_END__ (read-only section) and __frame_dummy_init_array_entry (text section) is almost 8K.
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on August 14, 2019, 08:58:54 PM
Hi jazzbiker
It seems everytime  Class  transitions between  Read Only Data (R or r)  and  Code (T or t)  a large block of padding gets
added. The column to the right of  Section  is the number of bytes between the current line and the previous line. You can
see that number spikes at each transition:
Code: [Select]
"tc@E310:~/rotdash$ nm -n -S -t d -a -f sysv rotdash"                                                   
                                                                                                       
                                                                                                       
"Symbols from rotdash:"                                                                                 
                                                                                                       
Name                                                       Value  Class    Type  Size      Section     
                                                                                                       
__gmon_start__                                                    w      NOTYPE              *UND*     
__libc_start_main@@GLIBC_2.0                                      U        FUNC              *UND*     
access@@GLIBC_2.0                                                 U        FUNC              *UND*     
chdir@@GLIBC_2.0                                                  U        FUNC              *UND*     
fflush@@GLIBC_2.0                                                 U        FUNC              *UND*     
printf@@GLIBC_2.0                                                 U        FUNC              *UND*     
usleep@@GLIBC_2.0                                                 U        FUNC              *UND*     
                                                               0  a        FILE              *ABS*     
.comment                                                       0  n                                     
crtstuff.c                                                     0  a        FILE              *ABS*     
crtstuff.c                                                     0  a        FILE              *ABS*     
init.c                                                         0  a        FILE              *ABS*     
rotdash.c                                                      0  a        FILE              *ABS*     
static-reloc.c                                                 0  a        FILE              *ABS*     
.interp                                                134513012  r                                     
.note.ABI-tag                                          134513032  r                                   20
.hash                                                  134513064  r                                   32
.gnu.hash                                              134513124  r                                   60
.dynsym                                                134513160  r                                   36
.dynstr                                                134513320  r                                  160
.gnu.version                                           134513430  r                                  110
.gnu.version_r                                         134513452  r                                   22
.rel.dyn                                               134513484  r                                   32
.rel.plt                                               134513500  r                                   16
.init                                                  134516736  t                                 3236
_init                                                  134516736  T        FUNC              .init     0
.plt                                                   134516768  t                                   32
.text                                                  134516880  t                                  112
main                                                   134516880  T        FUNC   140        .text     0
_start                                                 134517020  T        FUNC              .text   140
__x86.get_pc_thunk.bx                                  134517056  T        FUNC     4        .text    36
deregister_tm_clones                                   134517060  t        FUNC              .text     4
register_tm_clones                                     134517100  t        FUNC              .text    40
__do_global_dtors_aux                                  134517154  t        FUNC              .text    54
frame_dummy                                            134517184  t        FUNC              .text    30
__libc_csu_init                                        134517186  T        FUNC    79        .text     2
__libc_csu_fini                                        134517265  T        FUNC     1        .text    79
.fini                                                  134517268  t                                    3
_fini                                                  134517268  T        FUNC              .fini     0
.rodata                                                134520832  r                                 3564
_fp_hw                                                 134520832  R      OBJECT     4      .rodata     0
_IO_stdin_used                                         134520836  R      OBJECT     4      .rodata     4
.eh_frame                                              134520852  r                                   16
__FRAME_END__                                          134520852  r      OBJECT          .eh_frame     0
.init_array                                            134528772  t                                 7920
__frame_dummy_init_array_entry                         134528772  t      OBJECT        .init_array     0
__init_array_start                                     134528772  t      NOTYPE        .init_array     0
.fini_array                                            134528776  t                                    4
__do_global_dtors_aux_fini_array_entry                 134528776  t      OBJECT        .fini_array     0
__init_array_end                                       134528776  t      NOTYPE        .init_array     0
.dynamic                                               134528780  d                                    4
_DYNAMIC                                               134528780  d      OBJECT           .dynamic     0
.got                                                   134529020  d                                  240
.got.plt                                               134529024  d                                    4
_GLOBAL_OFFSET_TABLE_                                  134529024  d      OBJECT           .got.plt     0
.data                                                  134529060  d                                   36
__data_start                                           134529060  D      NOTYPE              .data     0
data_start                                             134529060  W      NOTYPE              .data     0
__dso_handle                                           134529064  D      OBJECT              .data     4
.bss                                                   134529068  b                                    4
__TMC_END__                                            134529068  D      OBJECT              .data     0
__bss_start                                            134529068  B      NOTYPE               .bss     0
_edata                                                 134529068  D      NOTYPE              .data     0
stdout@@GLIBC_2.0                                      134529068  B      OBJECT     4         .bss     0
completed.6835                                         134529072  b      OBJECT     1         .bss     4
_end                                                   134529076  B      NOTYPE               .bss     4
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: jazzbiker on August 15, 2019, 08:31:42 AM
Hi, Rich!
This gaps grows along with the gcc version numbers. I tried the same test with gcc 5.4 and found this gaps in the same places, but being smaller ones.
Gcc is so powerfull and versatile, using it for tiny programs is like stirring the sugar in a tea with the drill )
Your case opened my eyes on tcc, thanks!
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: jazzbiker on August 15, 2019, 10:59:17 PM
Stirring sugar again
Code: [Select]
tc@box:/tmp$ gcc -c rotdash.c
tc@box:/tmp$ tcc -o rotdash rotdash.o
tc@box:/tmp$ sstrip rotdash
tc@box:/tmp$ ls -l rotdash*
-rwxr-xr-x    1 tc       staff         1280 Aug 16 08:54 rotdash
-rw-------    1 tc       staff          317 Aug 16 08:53 rotdash.c
-rw-r--r--    1 tc       staff         1156 Aug 16 08:54 rotdash.o
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on August 17, 2019, 11:26:22 PM
Hi jazzbiker
I did a little digging and I think I figured out some of the reasons for the larger executables. The default linker script changed.
From:
elf_i386.xc      # Combines and sorts relocatable sections.
To:
elf_i386.xce    # Combines and sorts relocatable sections with a separate code segment.

The formula used to compute gap sizes between code and data changed.

This is the result if you specify the  elf_i386.xbn  script (Mix code & data on same page; don't align data):
Code: [Select]
tc@E310:~/rotdash$ gcc  -march=i486 -mtune=i686 -Os -pipe -Wall rotdash.c -o rotdash -Wl,-T/usr/local/lib/ldscripts/elf_i386.xbn
tc@E310:~/rotdash$ ls -l rotdash
-rwxr-xr-x 1 tc staff 4704 Aug 18 01:48 rotdash
tc@E310:~/rotdash$ sstrip rotdash
tc@E310:~/rotdash$ ls -l rotdash
-rwxr-xr-x 1 tc staff 1656 Aug 18 01:48 rotdash
tc@E310:~/rotdash$
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Juanito on August 18, 2019, 05:32:57 AM
Interesting - there's something I was not aware of..
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Rich on March 15, 2020, 10:58:50 PM
Hi Juanito and jazzbiker
I did a further writeup on executable sizes here if anyones interested:
http://forum.tinycorelinux.net/index.php/topic,23623.0.html
Title: Re: filetool.sh TC 10.1 trivial display bug: trailing slash in output
Post by: Juanito on March 16, 2020, 12:31:44 AM
Thanks for that - I recompiled rotdash for CorePure between tc-10.x and tc-11.x - there was a small reduction in size, presumably because the original was from 4.x..