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

libewf: on Linux check for system library first? #111

Open
darealshinji opened this issue Oct 20, 2023 · 3 comments
Open

libewf: on Linux check for system library first? #111

darealshinji opened this issue Oct 20, 2023 · 3 comments

Comments

@darealshinji
Copy link
Collaborator

darealshinji commented Oct 20, 2023

Wouldn't it make sense on Linux to look for libewf.so.2 in the system directories first and then try to load the bundled library?
I also think the extra FileExists() checks aren't needed.

  {$ifdef Linux}
    // look for system library first
    fLibHandle := LoadLibrary('libewf.so.2');

    {$ifdef CPU64}
    // on 64 bit systems look for our own library next
    if fLibHandle = nilhandle then
    begin
      libFileName := ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER)+'libewf-Linux-x64.so';
      fLibHandle := LoadLibrary(libFileName);
    end
    {$endif}

    if fLibHandle <> nilhandle then
    begin
      // success
    end
  {$endif}
@tedsmith
Copy link
Owner

I can see the logic, but, the "problem" with that library (from my perspective) is it is updated (well maintained) regularly. If QH uses the system SO.2 file that was not shipped with QH, there's a good chance some of the function calls will, at some stage, maybe sooner rather than later, start to fail. At least by making it call the shipped SO file that I compiled for distribution with QH itself, I know that all my calls from QH will work with that library, until the time comes that I recompile the libewf library myself.

@darealshinji
Copy link
Collaborator Author

If QH uses the system SO.2 file that was not shipped with QH, there's a good chance some of the function calls will, at some stage, maybe sooner rather than later, start to fail.

As long as the library doesn't receive any updates that break the current API the soname libewf.so.2 will stay the same, otherwise the number will be bumped to libewf.so.3 etc, in which case loading will fail anyway.

Additionally you could put the GetProcAddress part into a separate function so if loading the system library succeeds but loading the symbols fails you can fall back to the bundled library (pseudo code):

HANDLE handle;

function load_ewf_library(string filename) -> bool
{
  handle = LoadLibrary("libewf.so.2");
  if (!handle) return false;

  if (load_symbol_addresses(handle) == false) {
    FreeLibrary(handle);
    return false;
  }

  return true;
}

// ...

if (load_ewf_library("libewf.so.2") == false &&
   load_ewf_library(bundled_library_path) == false)
{
  // error: cannot load library
}

@darealshinji
Copy link
Collaborator Author

darealshinji commented Nov 5, 2023

Here you can find a modified version: https://github.com/darealshinji/quickhash/tree/libewf

Here's the diff with the changes: darealshinji@913fb85

It builds but I haven't checked if it actually does what it's supposed to do.

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

No branches or pull requests

2 participants