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

apparent bug: 'invalid ELF header' #450

Closed
o-jasper opened this issue Feb 22, 2012 · 24 comments
Closed

apparent bug: 'invalid ELF header' #450

o-jasper opened this issue Feb 22, 2012 · 24 comments
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@o-jasper
Copy link

julia> libc = dlopen("libc")
/usr/lib/libc.so: invalid ELF header
could not load module libc
 in dlopen at /home/jasper/oproj/programs/julia/j/base.j:97

I am in version 3458255(...) on (64 bit)Arch Linux. Glibc version 2.15-6. Other libraries, like libnova do seem to work. Bit of a bummer that it is exactly the one from the example to break. Tried to grab another libc.so, to see if it but failed(accidentally got 32, file wont open)

The functions of regex.h are in there right? I wanted to make destructuring-regex(as i wrote for Common Lisp), but for julia. (Basically, the idea is that results and what is between results go straight into variables.)

@JeffBezanson
Copy link
Member

I've found that in many linux distros libc.so is actually a linker script, and the dynamic linker locates this as the library but is not able to use it! This is very frustrating. Fortunately, julia is already linked against libc so the symbols are available in the "default" library via ccall(:getpid, ...) etc.

We have a regex library using pcre (j/regex.j); you will probably want to use those functions in some way.

@StefanKarpinski
Copy link
Member

Let's have a discussion of what you're thinking with the regex business. What we have now is serviceable and certainly no worse than what's in various scripting languages, but a better design could certainly be quite possible.

@StefanKarpinski
Copy link
Member

I think the dev list is probably a good place for such a discussion.

@o-jasper
Copy link
Author

I'll poke around a bit and see if i can make an analogous destructuring-regex and post to the dev list then.(though the name should probably be more descriptive.)

Ok that the issue is closed, but maybe change the error message for the things Julia is already linked against?

@JeffBezanson
Copy link
Member

We could parse the linker script ourselves to find the real file name. It seems absurd that applications would all need to implement this logic. Obviously the linker script thing is a half-implemented feature.
For reference, here is a patch to GHC that implements this feature:

http://hackage.haskell.org/trac/ghc/attachment/ticket/2615/T2615a.dsend

@JeffBezanson JeffBezanson reopened this Feb 23, 2012
@JeffBezanson
Copy link
Member

Probably good to remove most of src/dlload.c and implement dlopen in julia for easier parsing.

@o-jasper
Copy link
Author

@StefanKarpinski i posted on the mailing list about it. Goodnight&have a nice weekend. Update: forked it, and updated, of which julia/j/regex.j contains a newer version of the macro.

@ViralBShah
Copy link
Member

@JeffBezanson Can src/dlload.c be moved to julia without any bootstrapping issues. Would loading it early enough in sysimg.j be good enough?

@ViralBShah
Copy link
Member

Doesn't propose a solution, but discusses the problem. Can we run the script /lib and figure where the real version is, and then load that?

http://askubuntu.com/questions/40416/why-is-lib-libc-so-6-missing

@JeffBezanson
Copy link
Member

AFAIK all you can do is parse the thing yourself, it's not executable or anything.

@ViralBShah
Copy link
Member

How does gcc do it?

-viral

On 10-Mar-2012, at 11:29 PM, [email protected] wrote:

AFAIK all you can do is parse the thing yourself, it's not executable or anything.


Reply to this email directly or view it on GitHub:
#450 (comment)

@ViralBShah
Copy link
Member

I believe ldconfig does the work in identifying the right thing.

-viral

On 10-Mar-2012, at 11:29 PM, [email protected] wrote:

AFAIK all you can do is parse the thing yourself, it's not executable or anything.


Reply to this email directly or view it on GitHub:
#450 (comment)

@JeffBezanson
Copy link
Member

But is there any way we can take advantage of that functionality?

@ViralBShah
Copy link
Member

Douglas Bates wrote to a debian dev, who said he doesn't know himself. The suggestion was to write to debian-devel.

-viral

On 11-Mar-2012, at 8:16 AM, [email protected] wrote:

But is there any way we can take advantage of that functionality?


Reply to this email directly or view it on GitHub:
#450 (comment)

@nolta
Copy link
Member

nolta commented Mar 11, 2012

Seems like it might be doable:

nolta@ubuntu1110:~/julia$ ldconfig -p | grep libc.so
    libc.so.6 (libc6, OS ABI: Linux 2.6.15) => /lib/i386-linux-gnu/libc.so.6
nolta@ubuntu1110:~/julia$ ./julia
               _
   _       _ _(_)_     |
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  A fresh approach to technical computing
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.0.0+1331430882.r69af
 _/ |\__'_|_|_|\__'_|  |  Commit 69afb7032d (2012-03-10 20:54:42)
|__/                   |

julia> x = dlopen("/lib/i386-linux-gnu/libc.so.6")
Ptr{Void} @0xb783ab08

@nolta
Copy link
Member

nolta commented Mar 15, 2012

extras/openlib.jl appears to fix this problem.

@staticfloat
Copy link
Member

Confirmed, the following works on both my OSX 10.8.2 x86_64 laptop and my Linux i386 VM:

julia> require("extras/openlib.jl")

julia> Openlib.openlib("libc")
Ptr{Void} @0x00007f94ed2adc00

KristofferC pushed a commit that referenced this issue Jul 3, 2018
* Refactor `parse_package` and add unit tests

* Fold repl unit tests into repl.jl
@grep0
Copy link

grep0 commented Sep 6, 2018

Still an issue after 6 years

julia> ccall((:clock, :libc), Int32, ())
ERROR: error compiling top-level scope: could not load library "libc"
/usr/lib/x86_64-linux-gnu/libc.so: invalid ELF header
julia> ccall((:clock, "/lib/x86_64-linux-gnu/libc.so.6"), Int32, ())
1000525

Debian 4.17 x86_64

@yuyichao
Copy link
Contributor

yuyichao commented Sep 6, 2018

This is now intentional

@pengwyn
Copy link

pengwyn commented Sep 26, 2018

If this is intentional then perhaps a different example in the docs (https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/) might be needed? Or perhaps those examples (for :clock, :getent, :gethostname) should remove the "libc" part of their calls with an explanation for why that is needed.

@introspection3
Copy link

is fatal bug!!!! centos ERROR: error compiling top-level scope: could not load library "libc"

@introspection3
Copy link

when and how to solve this bug

@introspection3
Copy link

v1.0 v.11

@StefanKarpinski
Copy link
Member

Please post questions to the Julia discourse discussion forum.

LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Oct 11, 2021
cmcaine pushed a commit to cmcaine/julia that referenced this issue Nov 11, 2022
ViralBShah pushed a commit that referenced this issue Nov 9, 2023
Stdlib: SparseArrays
URL: https://github.com/JuliaSparse/SparseArrays.jl.git
Stdlib branch: main
Julia branch: master
Old commit: 3582898
New commit: 37fc321
Julia version: 1.11.0-DEV
SparseArrays version: 1.11.0
Bump invoked by: @ViralBShah
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaSparse/SparseArrays.jl@3582898...37fc321

```
$ git log --oneline 3582898..37fc321
37fc321 test: relax allocated tests (#468)
bd2bda8 replace ind2sub/sub2ind by CartesianIndices/LinearIndices (#451)
7897f1f test: somewhat more permissive test_throws message (#466)
911cf6a `reverse` for sparse vector/matrix (#450)
713a260 Define algebraic operators for SparseMatrixCSCView (#458)
f455a8e Add messages to DimensionMismatch errors (#461)
81fc6f3 Aggressive constprop in sparse * dense (#460)
0b36fdd fix h/vcat invoke dispatch arguments (#464)
6b23902 Add Finch to list of External Julia Sparse Array Libraries (#462)
```

Co-authored-by: Dilum Aluthge <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

10 participants