Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unrar not working with version error reporting in UI #2832

Closed
kkcarlc opened this issue Apr 6, 2024 · 58 comments
Closed

Unrar not working with version error reporting in UI #2832

kkcarlc opened this issue Apr 6, 2024 · 58 comments
Labels

Comments

@kkcarlc
Copy link

kkcarlc commented Apr 6, 2024

SABnzbd version

4.2.3 [e7e06de]

Operating system

Debian (SABnzbd installed via Flatpak)

Using Docker image

None

Description

After upgrading to version 4.2.3 via flatpak distributed via Flathub remote, a new error is showing in the UI:

Your UNRAR version is 0.00, we recommend version 5.50 or higher.

After downloading binary news, the files are not unrar'ed.

No changes have been made to the host environment, and this issue is verified not present in 4.2.2. The unrar version on the host is the nonfree version with version number 6.2.6.

I am not sure if this is impacting non-flatpak installs, or if flatpak installs are supported, but I wanted to file to bring attention to this issue.

@kkcarlc kkcarlc added the Bug label Apr 6, 2024
@thezoggy
Copy link
Contributor

thezoggy commented Apr 6, 2024

it should be installing the non-free unrar and you should have unrar 7.0.0

/usr/bin/unrar-nonfree -> /usr/bin/unrar

@kkcarlc
Copy link
Author

kkcarlc commented Apr 6, 2024

@thezoggy Ok so I understand, you are saying that unrar-nonfree >= 7 is a hard dependency on the host?

I can try to install that and retest and will update here.

@thezoggy
Copy link
Contributor

thezoggy commented Apr 6, 2024

no, im saying that it should have installed the unrar-nonfree. as you have no version im guessing you have the unrar-free version (which isnt supported).

do unrar within that flatpak and see what it has

@Safihre
Copy link
Member

Safihre commented Apr 6, 2024

@francoism90 ?

@sanderjo
Copy link
Contributor

sanderjo commented Apr 6, 2024

I'm surprised, because the SABnzbd flatpak brings it own unrar: https://github.com/flathub/org.sabnzbd.sabnzbd/blob/master/org.sabnzbd.sabnzbd.yaml#L84-L90C13

@kkcarlc what does you sabnzbd.log say related to this:

2024-04-06 08:31:44,918::INFO::[sabnzbdplus:459] UNRAR binary... found (/usr/bin/unrar)
2024-04-06 08:31:44,918::INFO::[sabnzbdplus:467] UNRAR binary version 7.00

@kkcarlc
Copy link
Author

kkcarlc commented Apr 6, 2024

unrar-nonfree >= 7 was not in backports debian. I downloaded and compiled source to version 7.0.7 and it is first in my path:

which unrar
=> /usr/local/bin/unrar
unrar |grep Copyright
=> UNRAR 7.00 freeware      Copyright (c) 1993-2024 Alexander Roshal

I had some permission overrides that I reset to the defaults and reinstalled the flatpak with flatpak --user install --reinstall org.sabnzbd.sabnzbd.

Entering the flatpak with flatpak enter org.sabnzbd.sabnzbd /bin/bash there is no unrar binary.

dpkg -s unrar-free
dpkg-query: package 'unrar-free' is not installed and no information is available

@kkcarlc
Copy link
Author

kkcarlc commented Apr 6, 2024

@sanderjo Last log I have is from 2023 and it says:

2023-11-25 02:03:07,212::INFO::[SABnzbd:460] UNRAR binary... found (/app/bin/unrar)
2023-11-25 02:03:07,212::INFO::[SABnzbd:468] UNRAR binary version 6.24

Looking at the settings UI in parameters it looks like the app is started with --disable-file-log. Is there another place I should look?

@sanderjo
Copy link
Contributor

sanderjo commented Apr 6, 2024

Ouch ... I can confirm on my Ubuntu ... running on a very old laptop with B820 Celeron from 2012. So is this the unrar with too high CPU features?

@kkcarlc on what CPU are you running it?

sander@xubuntu:~$ flatpak run org.sabnzbd.sabnzbd

2024-04-06 08:53:15,583::INFO::[SABnzbd:1144] --------------------------------
2024-04-06 08:53:15,584::INFO::[SABnzbd:1145] SABnzbd.py-4.2.3
2024-04-06 08:53:15,584::INFO::[SABnzbd:1155] Commit = e7e06dea419a03bfe179af64b7a69398f652a7b9

2024-04-06 08:53:16,270::INFO::[SABnzbd:458] UNRAR binary... found (/app/bin/unrar)
2024-04-06 08:53:16,270::INFO::[notifier:142] Sending notification: Warning - Your UNRAR version is 0.00, we recommend version 5.50 or higher.<br />

@kkcarlc
Copy link
Author

kkcarlc commented Apr 6, 2024

@sanderjo Running on a Intel(R) Pentium(R) Silver J5005 CPU @ 1.50GHz

@francoism90
Copy link
Contributor

francoism90 commented Apr 6, 2024

Please do not install unrar on your own system (unless you need to)!

The Flatpak includes the unrar bin, so it matches the correct/recommended spec of the app itself. :)

I'll check if I'm having the same error, because I did bump unrar and other deps.

Maybe the path inside de Flatpak differs, which could be possible.

@thezoggy I'm using the unrar-src package from RarLab itself.

@kkcarlc
Copy link
Author

kkcarlc commented Apr 6, 2024

@francoism90 I do see the path from the recent logs shared above as /app/bin/unrar. Looking inside the flatpak I see that path and it is an ELF, but running it to see default output for version information returns Illegal instruction.

@francoism90
Copy link
Contributor

@kkcarlc Thanks for reporting! Think it may be caused because I've bump unrar-src. 🤔

Not on the computer right now, will check later today.

@sanderjo
Copy link
Contributor

sanderjo commented Apr 6, 2024

running it to see default output for version information returns Illegal instruction.

So ... related to / same as linuxserver/docker-unrar#4 ? So the new -march=native in makefile causing problems on older x86 hardware. But, to be honest, only when really using unrar, not on the plain version check.

Because: compile option of unrar (as provided by rarlab) compiles for "recent" x86 hardware. Gives problems on old x86 hardware.

EDIT

I don't know if this is relevant / legal at all, but on my 2012 Celeron, I get this:

sander@xubuntu:~$ find /var/lib/flatpak/ | grep unrar
/var/lib/flatpak/app/org.sabnzbd.sabnzbd/x86_64/stable/6607429e23b1445664584939d1970eb317f0d0eedef144e0b142f5c5d3df2c5c/files/bin/unrar
sander@xubuntu:~$ /var/lib/flatpak/app/org.sabnzbd.sabnzbd/x86_64/stable/6607429e23b1445664584939d1970eb317f0d0eedef144e0b142f5c5d3df2c5c/files/bin/unrar
/var/lib/flatpak/app/org.sabnzbd.sabnzbd/x86_64/stable/6607429e23b1445664584939d1970eb317f0d0eedef144e0b142f5c5d3df2c5c/files/bin/unrar: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.38' not found (required by /var/lib/flatpak/app/org.sabnzbd.sabnzbd/x86_64/stable/6607429e23b1445664584939d1970eb317f0d0eedef144e0b142f5c5d3df2c5c/files/bin/unrar)

Not a core dump, but might be bad. I don't know

EDIT 2:

I installed flatpak & flatpak-sabnzbd on my modern x86, and

  1. flatpak-sabnzbd runs without problems, with correct unrar version reported.
  2. the direct unrar run also results in an error, so not a relevant nor valid method
sander@zwart2204:~$ flatpak run org.sabnzbd.sabnzbd

2024-04-06 10:25:09,731::INFO::[SABnzbd:458] UNRAR binary... found (/app/bin/unrar)
2024-04-06 10:25:09,732::INFO::[SABnzbd:466] UNRAR binary version 7.00

This confirms my hypothesis that the flatpak itself is correct, with unrar, but only for new hardware, due to the compile option in the rarlab provided makefile.
Solution: the flatpak build process should change the makefile before making/compiling.

@francoism90
Copy link
Contributor

francoism90 commented Apr 6, 2024

For the record, this my complete start output:

$ flatpak run org.sabnzbd.sabnzbd
2024-04-06 10:22:21,140::INFO::[SABnzbd:1144] --------------------------------
2024-04-06 10:22:21,140::INFO::[SABnzbd:1145] SABnzbd.py-4.2.3
2024-04-06 10:22:21,140::INFO::[SABnzbd:1155] Commit = e7e06dea419a03bfe179af64b7a69398f652a7b9
2024-04-06 10:22:21,140::INFO::[SABnzbd:1157] Full executable path = /app/bin/SABnzbd.py
2024-04-06 10:22:21,140::INFO::[SABnzbd:1158] Arguments = "/app/bin/SABnzbd.py"
2024-04-06 10:22:21,140::INFO::[SABnzbd:1159] Python-version = 3.11.8 (main, Nov 10 2011, 15:00:00) [GCC 13.2.0]
2024-04-06 10:22:21,140::INFO::[SABnzbd:1160] Dockerized = False
2024-04-06 10:22:21,141::INFO::[SABnzbd:1161] CPU architecture = x86_64
2024-04-06 10:22:21,142::INFO::[SABnzbd:1164] Platform = posix - Linux-6.8.1-300.fc40.x86_64-x86_64-with-glibc2.38
2024-04-06 10:22:21,143::INFO::[SABnzbd:1170] Preferred encoding = UTF-8
2024-04-06 10:22:21,143::INFO::[SABnzbd:1192] SSL version = OpenSSL 3.1.5 30 Jan 2024
2024-04-06 10:22:21,144::INFO::[SABnzbd:1201] Certifi version = 2024.02.02
2024-04-06 10:22:21,145::INFO::[SABnzbd:1202] Loaded additional certificates from /app/lib/python3.11/site-packages/certifi/cacert.pem
2024-04-06 10:22:21,145::INFO::[SABnzbd:1212] Using INI file /var/home/user/.sabnzbd/sabnzbd.ini
2024-04-06 10:22:21,146::INFO::[postproc:143] Loading postproc queue
2024-04-06 10:22:21,147::INFO::[scheduler:190] Scheduling RSS interval task every 60 min (delay=22)
2024-04-06 10:22:21,147::INFO::[scheduler:200] Scheduling version check in 10 minutes and daily at 15:5
2024-04-06 10:22:21,147::INFO::[scheduler:225] Setting schedule for midnight BPS reset
2024-04-06 10:22:21,147::INFO::[scheduler:234] Setting schedule for midnight server expiration check
2024-04-06 10:22:21,147::INFO::[scheduler:243] Setting schedule for server quota check
2024-04-06 10:22:21,147::INFO::[__init__:323] All processes started
2024-04-06 10:22:21,147::INFO::[SABnzbd:338] Template location for Glitter is /app/bin/interfaces/Glitter
2024-04-06 10:22:21,148::INFO::[SABnzbd:338] Template location for Config is /app/bin/interfaces/Config
2024-04-06 10:22:21,149::INFO::[misc:1230] [N/A] Running external command: ['/app/bin/unrar']
2024-04-06 10:22:21,152::INFO::[misc:1230] [N/A] Running external command: ['/app/bin/7z']
2024-04-06 10:22:21,169::INFO::[misc:1230] [N/A] Running external command: ['/app/bin/par2', '-V']
2024-04-06 10:22:21,174::INFO::[SABnzbd:423] SABCTools module (v8.1.0)... found!
2024-04-06 10:22:21,174::INFO::[SABnzbd:424] SABCTools module is using SIMD set: AVX2
2024-04-06 10:22:21,174::INFO::[SABnzbd:425] SABCTools module is linked to OpenSSL: True
2024-04-06 10:22:21,174::INFO::[SABnzbd:445] Cryptography module (v42.0.5)... found!
2024-04-06 10:22:21,175::INFO::[SABnzbd:451] par2 binary... found (/app/bin/par2)
2024-04-06 10:22:21,175::INFO::[SABnzbd:458] UNRAR binary... found (/app/bin/unrar)
2024-04-06 10:22:21,175::INFO::[SABnzbd:466] UNRAR binary version 7.00
2024-04-06 10:22:21,175::INFO::[SABnzbd:473] 7za binary... found (/app/bin/7z)
2024-04-06 10:22:21,175::INFO::[SABnzbd:475] 7za binary version 17.05
2024-04-06 10:22:21,175::INFO::[SABnzbd:481] nice binary... found (/usr/bin/nice)
2024-04-06 10:22:21,175::INFO::[SABnzbd:485] ionice binary... found (/usr/bin/ionice)
...

I can also enter it fine, and execute unrar:

flatpak enter org.sabnzbd.sabnzbd bash
$ /app/bin/unrar -v

UNRAR 7.00 freeware      Copyright (c) 1993-2024 Alexander Roshal

@kkcarlc Just a few questions:

@sanderjo I prefer upstream to solve this, instead of adjusting flags. Do other Flatpaks have issues with unrar as well? Did anyone contact RarLab?

@sanderjo
Copy link
Contributor

sanderjo commented Apr 6, 2024

Ah, that test method is nice! It works ... as long as flatpak-sabnzbd is running (so just like with docker):

On my recent x86:

sander@zwart2204:~$ flatpak enter org.sabnzbd.sabnzbd bash
bash-5.2$ /app/bin/unrar | head

UNRAR 7.00 freeware      Copyright (c) 1993-2024 Alexander Roshal

Usage:     unrar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract/>

<Commands>
  e             Extract files without archived paths
  l[t[a],b]     List archive contents [technical[all], bare]
  p             Print file to stdout
bash-5.2$ exit
exit

I'll have access to the old x86 tonight, so I can test then. In the meantime OP @kkcarlc could do that.

Your questions:

  1. flathub from cli
  2. no, not tested
  3. no, not tested

Note: I'm not a flatpak user; I just installed flatpak for this github issue.

Regarding upstream: clear. I don't know if that is happening at rarlab.

@francoism90
Copy link
Contributor

@sanderjo Thanks for testing! :)

Yeah, if this is an unrar-src issue, it may also affects users outside the docker/flatpak/etc. sandbox. I try to avoid adjusting flags and makefiles, as upstream should handle these cases (in my opinion at least - excluding 'simple' stuff like paths, etc.).

@jcfp
Copy link
Member

jcfp commented Apr 6, 2024

@francoism90 optimizing for the native arch of the system during compile only makes sense in case the compiled program is either only ever used on that very system, or compatibility between that system and all other 100% guaranteed.

As soon as you end up distributing to other systems without the luxury of that degree of compatibility (e.g. anything from flatpak to linux distributions) you don't really have a choice but to target a certain common hardware baseline and instruction set, regardless of upstream's default compiler options. Any program that wants to go beyond that will have to rely on runtime detection of hardware features (which unrar supports just fine).

@sanderjo
Copy link
Contributor

sanderjo commented Apr 6, 2024

Ah, "good" news: I've got another old x86 (Intel(R) Core(TM) i7-2635QM ... from 2011), with Ubuntu 22.04, and flatpak-sabnzbd does show

Your UNRAR version is 0.00, we recommend version 5.50 or higher.
and I can confirm via your log-in-to-flatpak-to-run-unrar that that unrar fails

sander@MacMini:~$ flatpak enter org.sabnzbd.sabnzbd bash
bash-5.2$ /app/bin/unrar 
 Illegal instruction (core dumped)
bash-5.2$ /app/bin/unrar | head
bash-5.2$ 

@Safihre again I would like to suggest that SABnzbd checks the unrar output for the Illegal instruction (core dumped) to stderr (redirected to stdout), to avoid false "version 0.00" notifications, which leads users and us to think it's unrar-free. I think this is good in general; also for running other binaries.

@francoism90
Copy link
Contributor

francoism90 commented Apr 6, 2024

@sanderjo Could you please report your findings to RARLAB?
https://www.rarlab.com/feedback.htm

I'm willing to change the flags, if they say they are not going to fix it.
They don't have a public repo (just the source), if I'm not mistaken.

@sanderjo
Copy link
Contributor

sanderjo commented Apr 6, 2024

@francoism90 I believe that @Safihre is already doing that. He has a warm relation with rarlab.

@Safihre
Copy link
Member

Safihre commented Apr 6, 2024

Yep, I'll do that.

@francoism90
Copy link
Contributor

@jcfp I think Flatpak already handles this, as they do build the package (also for ARM).

In most cases, I don't think you should have to adjust flags for Flatpak/Docker/Snap, etc.
It overrules that -march=native option to a generic one inside the builder itself.

@sanderjo
Copy link
Contributor

sanderjo commented Apr 6, 2024

To add to (my) confusion (again): the unrar from rarlab does run on my i7. But then I don't understand yet why the flatpak-SABnzbd unrar version already fails.

Plain sabnzbd straight on Ubuntu 22.04 on my old 2011 i7, with unrar 7 from rarlab, does report the version correctly:

2024-04-06 11:27:33,186::INFO::[sabnzbdplus:474] 7za binary... found (/usr/bin/7zz)
2024-04-06 11:27:33,186::INFO::[sabnzbdplus:476] 7za binary version 21.07

So:

  • hard to reproduce. Not reproducable from CLI
  • and the flatpak-sabnzbd ... why does that dump core, both from sabnzbd and from the bash shell. Different environment? Or a different unrar? @francoism90 can you create a flatpak with the precompiled unrar from https://www.rarlab.com/rar/rarlinux-x64-700.tar.gz ?
sander@MacMini:~/rar$ ll
total 1612
drwxr-xr-x  2 sander sander   4096 feb 26 10:05 ./
drwxr-x--- 18 sander sander   4096 apr  6 11:08 ../
-rw-r--r--  1 sander sander   2721 feb 26 10:05 acknow.txt
-rwxr-xr-x  1 sander sander 248952 feb 26 10:05 default.sfx*
-rw-r--r--  1 sander sander   6753 feb 26 10:05 license.txt
-rw-r--r--  1 sander sander    428 feb 26 10:05 makefile
-rw-r--r--  1 sander sander   3326 feb 26 10:05 order.htm
-rwxr-xr-x  1 sander sander 774184 feb 26 10:05 rar*
-rw-r--r--  1 sander sander   1210 feb 26 10:05 rarfiles.lst
-rw-r--r--  1 sander sander 105756 feb 26 10:05 rar.txt
-rw-r--r--  1 sander sander    692 feb 26 10:05 readme.txt
-rwxr-xr-x  1 sander sander 441632 feb 26 10:05 unrar*
-rw-r--r--  1 sander sander  35626 feb 26 10:05 whatsnew.txt
sander@MacMini:~/rar$ ./unrar 

UNRAR 7.00 freeware      Copyright (c) 1993-2024 Alexander Roshal

Usage:     unrar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract/>

@sanderjo
Copy link
Contributor

sanderjo commented Apr 6, 2024

OK ... based on the above, I did something ugly, but it works:

copy the compiled unrar 7 binary from rarlab into the flatpak
run flatpak-sabnzbd ... and it works! Correct version, and an actual download with unpack works!

So @francoism90 is that acceptable & feasible for you? No compiling unrar, but getting the unrar compiled binary.

2024-04-06 11:41:35,381::INFO::[SABnzbd:458] UNRAR binary... found (/app/bin/unrar)
2024-04-06 11:41:35,381::INFO::[SABnzbd:466] UNRAR binary version 7.00
sander@MacMini:~$ find /var/lib/flatpak/ | grep unrar
/var/lib/flatpak/app/org.sabnzbd.sabnzbd/x86_64/stable/6607429e23b1445664584939d1970eb317f0d0eedef144e0b142f5c5d3df2c5c/files/bin/unrar
/var/lib/flatpak/app/org.sabnzbd.sabnzbd/x86_64/stable/6607429e23b1445664584939d1970eb317f0d0eedef144e0b142f5c5d3df2c5c/files/bin/unrar.org.6
/var/lib/flatpak/app/org.sabnzbd.sabnzbd/x86_64/stable/6607429e23b1445664584939d1970eb317f0d0eedef144e0b142f5c5d3df2c5c/files/bin/unrar.7

@francoism90
Copy link
Contributor

francoism90 commented Apr 6, 2024

@sanderjo I do not like this approach. We have seen what xz can cause for issues when you just include the bin, so I rather prefer to built it within the Flatpak itself, and also let it crash - just to make sure it can be fixed (either upstream or by adding a make flag).

Like I said before, this issue also exists outside Flatpak.

Edit: I also don't know if just including the unrar bin, works on ARM. Flatpak builds this for other archs as well.

@jcfp
Copy link
Member

jcfp commented Apr 6, 2024

@jcfp I think Flatpak already handles this, as they do build the package (also for ARM).

In most cases, I don't think you should have to adjust flags for Flatpak/Docker/Snap, etc. It overrules that -march=native option to a generic one inside the builder itself.

If they did, this issue wouldn't exist in the first place. If anything, flatpak builds may simply rely on compiler defaults; i.e., the low-end baseline most compilers (gcc and the likes) target by default unless instructed otherwise (e.g. via -march).

@francoism90
Copy link
Contributor

@jcfp We don't know if Flatpak is to blame here. Because @sanderjo already compiled unrar on an older system, and got the same error. @Safihre is contacted RARLab, and I think this is the correct approach.

It doesn't look the Flatpak Builder is doing wrong here, also because @sanderjo also linked to Docker build issues.

@Safihre
Copy link
Member

Safihre commented Apr 6, 2024

Got a very quick response from Rarlab. Think we need @animetosho input on this one:

Hello,

I added march=native after one ARM64 Unix user wrote to me that
__ARM_FEATURE_CRYPTO isn't defined without either march=native
or -march=armv8-a+crypto switches, so Neon AES instructions are not used.

I hadn't added -march=armv8-a+crypto to default makefile target,
because this target is supposed to be for different CPU architectures,
not for ARM only. So I added march=native.

I can remove it, but then I am not certain if Neon AES support will still
be included by default.

@animetosho
Copy link

animetosho commented Apr 6, 2024

__ARM_FEATURE_CRYPTO isn't defined without

It shouldn't be defined and he shouldn't be trying to make it defined.
I wrote a patch for unrar 6 which builds a binary without -march flags or requring __ARM_FEATURE_CRYPTO - he can use that as a reference on how to do it.

@kkcarlc
Copy link
Author

kkcarlc commented Apr 6, 2024

@francoism90 @sanderjo

* How did you install this flatpak? Using Flathub or Gnome Software?
* Did you try Flatpak repair? See https://docs.flatpak.org/en/latest/flatpak-command-reference.html#flatpak-repair, it depends if it's system or user installed.
* Do you have the same issue when building unrar-src?
  1. Installed via Flathub CLI. It is a --user install
  2. I used flatpak repair --user and it completed without issue. Starting the app in the log output:
2024-04-06 15:41:31,173::INFO::[SABnzbd:458] UNRAR binary... found (/app/bin/unrar)
2024-04-06 15:41:31,174::INFO::[notifier:142] Sending notification: Warning - Your UNRAR version is 0.00, we recommend version 5.50 or higher.<br />
To prevent all helpful warnings, disable Special setting 'helpful_warnings'. (type=warning, job_cat=None)
2024-04-06 15:41:31,174::WARNING::[misc:94] Your UNRAR version is 0.00, we recommend version 5.50 or higher.<br />
  1. I did not have the same issue when compiling from source. I used the default target make -f makefile. Running that version on the host does not show Illegal instruction and reports the 7.00 version correctly.

@kkcarlc
Copy link
Author

kkcarlc commented Apr 6, 2024

Rolling back to release 4.2.2 [f730607] via:

flatpak --user update --commit=1b93894a78966e8ec2005d49ab0faf8ffb90b5c0f1561dfa471a184eb6a25c02 org.sabnzbd.sabnzbd

confirms that the binary is shipped with the flatpak and is an older version.

flatpak enter org.sabnzbd.sabnzbd bash
/app/bin/unrar | head -2
#=> UNRAR 6.24 freeware      Copyright (c) 1993-2023 Alexander Roshal

The UI doesn't report the error of flatpak version 0.00 and a full functional test via the UI confirms that download and unpacking works.

@thezoggy
Copy link
Contributor

to note that lsio did change their build process a few weeks ago to drop CXXFLAGS=-march=x86-64-v2 and confirmed it fixed those that were having issues with illegal instruction problem.
so the docker mod for unrar6 shouldnt be needed for those..but they are going to keep it around in case.

i do believe only the nightly branch have gotten the update, so master/unstable at this time would still use dockermod until they do.

@francoism90
Copy link
Contributor

@thezoggy I'm I understanding correctly we need to wait for a version bump of unrar to fix this? :)

@thezoggy
Copy link
Contributor

thezoggy commented Apr 15, 2024

@thezoggy I'm I understanding correctly we need to wait for a version bump of unrar to fix this? :)

Depends, for the ARM64 one or what most of the people have complained about with it being busted in docker for those with legacy cpu.. its fallout of linuxserver using CXXFLAGS which they dropped on the nightly tag. If your using master/unstable you just gotta wait for them to pull in update (trigger force package) since they control their unrar themselves as they built it out for all their stuff. Or of course just build your own.

If using native unrar builds from rarlab and that one isnt working on a glibc system, then perhaps that build needs a bugfix (and if fixed in newer versions, then yes bump required if not silently replacing existing build). But it wasn't clear if what animetosho was talking about made it back to unrar dev to do anything.

Again all the ones I've seen of unrar being broken has just been due to lsio unrar trying to target modern cpu and they are just rocking old atom cpu or something that doesnt have full support for the instruction when that flag was used, but now after being dropped should have restored compatibility. other docker maintainers do use lsio unrar as well.. which is why it can get a little confusing when people talk about what doesnt or does work.

@Safihre
Copy link
Member

Safihre commented Apr 16, 2024

@animetosho I got a reply:

It compiles and works properly in macOS X.

But when I build Android RAR using Android NDK toolchain, I must specify
-march=armv8-a+crypto+crc Clang switch regardless of attributes I assigned
to blockEncryptNeon and blockDecryptNeon functions.

I tried:
__attribute__((target("crypto")))
__attribute__((target("+crypto")))
__attribute__((target("arch=armv8-a+crypto")))

In all these cases if I remove -march=armv8-a+crypto+crc Clang switch,
build failed with errors like:

undeclared identifier 'vaeseq_u8'

even though "#include <arm_neon.h>" was present. So now I am not certain
if we can use Neon instructions in Android NDK without appropriate
compiler switch.

If we really can't, it might indicate that some other build configurations
also require some kind of -march=... switch for Neon support.

@animetosho
Copy link

animetosho commented Apr 16, 2024

It looks like older versions of Clang have a bug where it hides functions behind define checks, so function-level arch targeting doesn't work for ARM.

If you want to support older compilers, the way to work around the issue would be to split arch specific functions to separate their own file, then use -march for those specific files (not the whole build). This is similar to how sabctools uses different flags for specific files.
Remember that -march=native is incorrect - you'll need to do -march=armv8-a+crypto for the file containing ARM crypto functions, and -maes for the file containing AES-NI functions. This does mean that your build system needs to know which flags valid for the target platform. How one approaches that depends on taste - you could have separate Makefiles and get the user to pick the correct target, or you could use a more comprehensive build system (CMake, Meson etc) which can detect supported flags by the compiler.

Maybe there's some workaround for Clang to make function-level targeting work. I think some libraries rely on this, so perhaps check those. But given that it works fine on Clang 17, I'm willing to chalk it up as a compiler bug more than anything else.
I suppose an alternative is to undermine the compiler and define your own intrinsic via inline assembly.

@Safihre
Copy link
Member

Safihre commented May 7, 2024

I am going to close this. There is nothing more we can do.. Rarlabs should fix this, we gave them all the suggestions by @animetosho.

@Safihre Safihre closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
@kkcarlc
Copy link
Author

kkcarlc commented May 7, 2024

So this effectively ends sabnzbd support for older cpus after version 4.2.2. I'm running sabnzbd on an older box. I think this would be more common than not. I understand the bug is upstream, but upstream should not be building with -march=native at all since that will use non generic instructions for the cpu that it is being compiled on.

Can upstream not support all x86-64 cpus with -march=x86-64 -mtune generic?

Is it possible to work around upstream by bind mounting unrar into the flatpak?

Should I contact upstream by discussing with them via email as suggested from their website?

I am not understanding the ARM64 argument. Different compilations need to happen for different architectures. Why is not the default x86 architecture to support older cpus?

@animetosho
Copy link

I am not understanding the ARM64 argument. Different compilations need to happen for different architectures. Why is not the default x86 architecture to support older cpus?

Presumably the dev doesn't know how to supply different flags for different archs, and doesn't want to supply a second Makefile, so they just throw a "it's fixed" -march=native in there and let others deal with it.
(though doing this would arguably still be wrong for ARM64, but it might not matter as much)

@thezoggy
Copy link
Contributor

thezoggy commented May 8, 2024

So this effectively ends sabnzbd support for older cpus after version 4.2.2. I'm running sabnzbd on an older box as a set-top. I think this would be more common than not. I understand the bug is upstream, but upstream should not be building with -march=native at all since that will use non generic instructions for the cpu that it is being compiled on.

Can upstream not support all x86-64 cpus with -march=x86-64 -mtune generic?

Is it possible to work around upstream by bind mounting unrar into the flatpak?

Should I contact upstream by discussing with them via email as suggested from their website?

I am not understanding the ARM64 argument. Different compilations need to happen for different architectures. Why is not the default x86 architecture to support older cpus?

Sab is not rar nor do we distribute rar on Linux. If your not happy with flatpak because of the packages it's installing then switch to something else that gives you the control or figure out how to update the env with what you want...

Someone submitted stuff to do snap.. which I guess is used for flatpak as well? I'm not familiar with how it's used to know if it's stage vs build package needs a change or what specifically it's not working for you. For what I've seen with reports the issue generally has been peoples builds were using the wrong march for the system.. which shouldn't be the case if it's just installing the package from your os..

If the unrar version isn't working for you because of who build it, try another build. If it's not working because of a bug, then try another version.

If its a bug with unrar that's installed on your os then might need to report it to unrar.. but again need to figure out if it's actually a problem with official build or something your building yourself or what

@kkcarlc
Copy link
Author

kkcarlc commented May 8, 2024

Isn't the value proposition of flatpak to work across environments? For those officially packaging software in flatpak it seems that it would fall under their purview. A collective shrug at the end of this isn't entirely unexpected, albeit disappointing.

However, there is no obligation to provide software in the first place, so I have no expectation nor entitlement in that regard. Sabnzbd is great software and I thank you for it. Additionally, thank you for spending the time looking into the issue.

@thezoggy
Copy link
Contributor

thezoggy commented May 8, 2024

Isn't the value proposition of flatpak to work across environments? For those officially packaging software in flatpak it seems that it would fall under their purview. A collective shrug at the end of this isn't entirely unexpected, albeit disappointing.

However, there is no obligation to provide software in the first place, so I have no expectation nor entitlement in that regard. Sabnzbd is great software and I thank you for it. Additionally, thank you for spending the time looking into the issue.

Per:
https://flathub.org/apps/org.sabnzbd.sabnzbd

It's meant for aarch64, x86_64.
However you are trying to use arm64 CPU?

@kkcarlc
Copy link
Author

kkcarlc commented May 8, 2024

No I am using x86_64. The discussion mentioning ARM was that upstream was patching for ARM and using -march=native to do that. I'm not sure the exact extent to what upstream was doing this.

This is my processor: Intel(R) Pentium(R) Silver J5005 CPU @ 1.50GHz
and machine:
uname -m => x86_64

I am not super familiar with building flatpak, but a workaround I was looking into was bind mounting into the app directory to provide my own unrar binary. However due to the sandboxing this seems unlikely since it is mounted ro.

Im looking into the possibility of cloning the Sabnzbd's flatpak repo and building myself. The problem mentioned above is that the unrar makefile is using -march=native which will optimize for the machine it is built on:

CXXFLAGS=-march=native -O2 -std=c++11 -Wno-logical-op-parentheses -Wno-switch -Wno-dangling-else

If I built this myself, I wouldn't have a problem and would have to package into the flatpak. However, I would only be solving the problem for myself. If possible, it would probably be better to patch that makefile before building with sed or the flatpak build "patches" mechanism so a fix would be provided for everybody.

@sanderjo
Copy link
Contributor

sanderjo commented May 8, 2024

a workaround I was looking into was bind mounting into the app directory to provide my own unrar binary. However due to the sandboxing this seems unlikely since it is mounted ro.

That worked for my setup (very old x86):
#2832 (comment)

@kkcarlc
Copy link
Author

kkcarlc commented May 8, 2024

@sanderjo I must have missed this. Are you saying that you patched the flatpak yaml with a download unrar binary and then rebuilt it? Or is there a bind mount option into the /app/bin directory that I am having trouble finding? From reading flatpak docs I thought this app directory was locked down and not allowed to be updated after flatpak is built.

@sanderjo
Copy link
Contributor

sanderjo commented May 8, 2024

No. I just installed the flatpak, found unrar in the installed flatpak directory structure, and copied the working unrar version onto it. No problems with mount nor read-only. No rebuilding.

So: find
find /var/lib/flatpak/ | grep unrar

hopefully it will say something like

/var/lib/flatpak/app/org.sabnzbd.sabnzbd/x86_64/stable/6607429e23b1445664584939d1970eb317f0d0eedef144e0b142f5c5d3df2c5c/files/bin/unrar

Get the unrar from rarlab. Check is works on your old x86 by actually unrarring a rar set (just running without unrarring seems not enough)
Then just copy that unrar over the flatpak version.

Worked for me.

@kkcarlc
Copy link
Author

kkcarlc commented May 8, 2024

@sanderjo Wow! I just copied my host unrar binary over and it worked as you mentioned. Thank you!

The location of those files were in $HOME/.local/share due to it being a user flatpak install. I was woefully unaware of these files even living in that location or that flatpak even worked like that. My mental model was more inline with a Docker container with binary packaged 'inside'.

Thanks everyone for their help on this.

I am very happy for this workaround, but I think a more robust fix would be able to patch the unrar makefile during the time of build of the flatpak to not include -march=native in case anyone else comes across this. However, it seems like there hasn't been a lot of others having this issue 🤷. Or course, I leave it to the maintainers to decide what to do long term. But I think this thread has served as good documentation.

Thanks again.

@sanderjo
Copy link
Contributor

sanderjo commented May 8, 2024

Cool.

The same seems to be the case for snap: all under /snap/, with files in plain sight.
Howerver, snap images are mounted, and mounted as ro, so not (easily) changeable

$ mount | grep snap | grep -i sabnzbd
/var/lib/snapd/snaps/sabnzbd_5618.snap on /snap/sabnzbd/5618 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)
/var/lib/snapd/snaps/sabnzbd_5642.snap on /snap/sabnzbd/5642 type squashfs (ro,nodev,relatime,errors=continue,threads=single,x-gdu.hide)

with for example

/snap/sabnzbd/5642/usr/bin/unrar

which is executable from the host (but not changeable, due to ro)

@kkcarlc
Copy link
Author

kkcarlc commented May 8, 2024

For completeness from gcc man page for x86 options:

       -march=cpu-type
           Generate instructions for the machine type cpu-type.  In contrast to  -mtune=cpu-type,
           which  merely  tunes  the  generated  code  for  the  specified  cpu-type, -march=cpu-type
           allows  GCC  to generate code that may not run at all on processors other than the one
           indicated.  Specifying -march=cpu-type implies -mtune=cpu-type, except where  noted otherwise.

           The choices for cpu-type are:

           native
               This selects the CPU to generate code for at compilation time by determining the processor 
               type of the compiling machine.   Using  -march=native  enables  all instruction  subsets
               supported  by the local machine (hence the result might not run on different machines).
               Using -mtune=native produces code optimized for the local machine under the constraints
               of the selected instruction set.

           x86-64
               A generic CPU with 64-bit extensions.

           ...

This selects the CPU to generate code for at compilation time by determining the processor type of the compiling machine.

Upstream most certainly wants something other than this since they do not know what machine unrar is going to run on. An x86-64 option would be the baseline for a generic x86-64 arch and should be the target unless specific instructions are being used requiring newer cpus.

Below is a patch in case SABnzbd was going to fix this or communicate with upstream to do so. I built with this on the machine I was having an issue with and placed it within the flatpak as @sanderjo mentioned above and it was successful.

diff --git a/makefile b/makefile
index ce54a02..2131549 100644
--- a/makefile
+++ b/makefile
@@ -3,7 +3,7 @@
 
 # Linux using GCC
 CXX=c++
-CXXFLAGS=-march=native -O2 -std=c++11 -Wno-logical-op-parentheses -Wno-switch -Wno-dangling-else
+CXXFLAGS=-march=x86-64 -O2 -std=c++11 -Wno-logical-op-parentheses -Wno-switch -Wno-dangling-else
 LIBFLAGS=-fPIC
 DEFINES=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DRAR_SMP
 STRIP=strip

@sanderjo
Copy link
Contributor

sanderjo commented May 8, 2024

I built with this on the machine I was having an issue with and placed it within the flatpak as @sanderjo mentioned above and it was successful.

AFAIK / AFAIR the Linux unrar from rarlabs (https://www.rarlab.com/download.htm ... currently "RAR 7.01 beta 1 for Linux x64") just works on old x86 hardware. Can you try? Saves you time.
If so, the problem is indeed in the flatpak packager recompiling unrar on modern hardware.

@kkcarlc
Copy link
Author

kkcarlc commented May 8, 2024

I built with this on the machine I was having an issue with and placed it within the flatpak as @sanderjo mentioned above and it was successful.

AFAIK / AFAIR the Linux unrar from rarlabs (https://www.rarlab.com/download.htm ... currently "RAR 7.01 beta 1 for Linux x64") just works on old x86 hardware. Can you try? Saves you time. If so, the problem is indeed in the flatpak packager recompiling unrar on modern hardware.

I can confirm that this also works on my problematic machine.

@sanderjo
Copy link
Contributor

sanderjo commented May 8, 2024

I can confirm that this also works on my problematic machine.

Yes. And that makes clear why the rarlab person has no real need to change his build process.

@sanderjo
Copy link
Contributor

sanderjo commented May 8, 2024

@Safihre can you put "Flatpak:" in the title of this issue so it's easy to find for others?

@kkcarlc
Copy link
Author

kkcarlc commented May 8, 2024

And that makes clear why the rarlab person has no real need to change his build process.

I agree partially with that. For now his build process works, but is machine dependent. The problem is the -march=native in the source. This is going to change wherever in the stream the package is built. It is a bad flag to have in a Makefile unless it is being compiled by all end users. That is not the case here since it is packaged on another build machine and distributed as a binary. So the rarlab upstream build machine might be ok for now but that really depends on the build machine and subject to change in the future. The real change that needs to happen is a source change to the makefile.

Edit: his build process works . For all machines new enough to understand instructions from his build machine. An explicit build target should be set for whatever machine instructions he is willing to support. And sounds like native was added to support an ARM instruction instead of providing another Makefile like @animetosho suggested.

@francoism90
Copy link
Contributor

I'm willing to make changes to support older architects, as the package needs to be bumped for the newest SAB version anyway.

What would be a good workaround? For now I'm thinking about changing the build flags, not something I really would like to see, but if Rarlab still hasn't fixed this, it may be the only thing to do.

@jcfp
Copy link
Member

jcfp commented May 8, 2024

What would be a good workaround? For now I'm thinking about changing the build flags, not something I really would like to see, but if Rarlab still hasn't fixed this, it may be the only thing to do.

You probably only need to drop the -march=native from the unrar makefile. From the patch applied to the Debian unrar package:

-CXXFLAGS=-march=native -O2 -std=c++11 -Wno-logical-op-parentheses -Wno-switch -Wno-dangling-else
+CXXFLAGS=-std=c++11 -Wno-logical-op-parentheses -Wno-switch -Wno-dangling-else

@kkcarlc
Copy link
Author

kkcarlc commented May 8, 2024

@francoism90 I agree with @jcfp's above comment. I commented up the thread to include a base target of x86-64, however that locks support into amd64 machines and not sure about the project supplying support for aarch64 in the future.

I tested a build with the C flags mentioned by @jcfp and it works.

My testing was:

  1. Built without -march=native on a linux distro that is rolling and has glibc 2.39. Copied this binary to the problem machine, and it failed since it running a stable distro with glibc 2.36. So dynamic linking was a problem.
  2. I built on a newer processor with a stable distro and -march=native enabled that links against 2.36, copied the binary over to the problem machine and it failed as we have seen throughout the discussion. (It optimized for newer hardware and threw an Illegal Instruction error).
  3. I rebuilt on newer processor stable machine without -march=native and copied it over and it works.

So flatpak is in a unique position here. Linux distros build without -march=native and link against a glibc that they know their users are going to use (since they also control glibc version). But flatpak has no guarantees of that. So the best thing to do is to build without -march=native on a "stable" distro with an older version of glibc (e.g. debian stable) since glibc is essentially backward compatible. That would give the flatpak releases enough coverage for most use cases. If users are using older than glibc 2.36 then at some point a line has to be drawn on support. I would expect that is not many.

Thanks for everyone's help on this.

@thezoggy
Copy link
Contributor

thezoggy commented May 9, 2024

@francoism90 I agree with @jcfp's above comment. I commented up the thread to include a base target of x86-64, however that locks support into amd64 machines and not sure about the project supplying support for aarch64 in the future.

I tested a build with the C flags mentioned by @jcfp and it works.

My testing was:

1. Built without `-march=native` on a linux distro that is rolling and has glibc 2.39. Copied this binary to the problem machine, and it failed since it running a stable distro with glibc 2.36. So dynamic linking was a problem.

2. I built on a newer processor with a stable distro and `-march=native` enabled that links against 2.36, copied the binary over to the problem machine and it failed as we have seen throughout the discussion. (It optimized for newer hardware and threw an Illegal Instruction error).

3. I rebuilt on newer processor stable machine _without_ `-march=native` and copied it over and it works.

So flatpak is in a unique position here. Linux distros build without -march=native and link against a glibc that they know their users are going to use (since they also control glibc version). But flatpak has no guarantees of that. So the best thing to do is to build without -march=native on a "stable" distro with an older version of glibc (e.g. debian stable) since glibc is essentially backward compatible. That would give the flatpak releases enough coverage for most use cases. If users are using older than glibc 2.36 then at some point a line has to be drawn on support. I would expect that is not many.

Thanks for everyone's help on this.

at one point lsio was replacing native with x86-64-v2 on their build, which resulted in the older cpu having the illegal instruction problems. they fixed their builds by reverting back to native, and i've seen their stuff work just fine on the problematic old atom/intel stuff just fine now.

they do static builds, which perhaps that might be something to do with the flatpak build.
taken from lsio they modify the makefile with:
sed -i 's|LDFLAGS=-pthread|LDFLAGS=-pthread -static|' makefile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants
@thezoggy @sanderjo @francoism90 @Safihre @jcfp @animetosho @kkcarlc and others