Ltrace not producing any output

I am working through the book Rust In Action (currently available through the Manning Early Access Program), and one of the author's debugging instructions is not working as expected. I don't know if there's actually anything wrong, maybe it's just a matter of peculiarities of different systems.

Anyway, there is an example program that is supposed to illustrate heap allocation, and the instructions say to compile the program with cargo build, then execute as follows:

timeout 20 ltrace -T -o trace.txt -e -*+malloc+free+realloc ./target/debug/particle

But for me, the trace.txt file does not contain any information, except for:

--- SIGTERM (Terminated) ---
+++ killed by SIGTERM +++

I searched for relevant info and didn't find much, but I did see a forum post somewhere indicating that ltrace might not work on PIE executables, so I tried

RUSTFLAGS='-g -C relocation-model=dynamic-no-pic' cargo build

... but that did not make any difference.

Anybody have an idea what I can do to make ltrace work as expected? I'm using Rust 1.47 on Manjaro Linux.

Try putting the -*+malloc+free+realloc part between quotes. Your shell likely intepreted the * as needing to find all files matching the pattern.

Try putting the -*+malloc+free+realloc part between quotes.

That was the first thing I tried - because zsh complained about the glob expression. But quoting didn't make any difference. Also, since I just recently switched to zsh and there's a lot I don't understand about it, I also tried running the command in bash with and without quotes. Unfortunately, none of those measures make any difference.

IIRC ltrace only works with PLT calls, but I'm not sure how to convince rustc to link that way. I think you need -Zrelro-level=off/partial and -Zplt=on, but that doesn't seem to be sufficient.

Use readelf -r your-file to see what kind of relocations it has.

PLT, eh? That's a new concept for me ...

So I might need to use the nightly toolchain? I use rustup, so that wouldn't be a problem, but I generally stick to stable versions unless there's a specific need to do otherwise.

[I don't think the author of the book intends for it to be this complicated. I mean, it's probably all useful knowledge, but I'm not sure how deep I want to go into this rabbit hole right now :wink: I have submitted feedback saying that the instructions need more testing before the book is finalized]

Okay, I did that, and I get:

Relocation section '.rela.dyn' at offset 0x17f8 contains 111 entries:
.... [111 lines omitted] ....
Relocation section '.rela.plt' at offset 0x2260 contains 6 entries:

So, not much PLT, I guess ... that's about all I understand right now.