3

I've never patched anything in Linux, and I can't exactly figure out what the guy who wrote this post (second paragraph) means. That target source is qemu from github and the changes to apply are:

diff --git a/linux-user/flatload.c b/linux-user/flatload.c
index 58f679e..c13a201 100644
--- a/linux-user/flatload.c
+++ b/linux-user/flatload.c
@@ -44,7 +44,7 @@
 #define ntohl(x) be32_to_cpu(x)
 #include 
 
-//#define DEBUG
+#define DEBUG
 
 #ifdef DEBUG
 #define        DBG_FLT(...)    printf(__VA_ARGS__)

This looks like a long diff command to me but attempting to execute it fails. After some searching, I though I had to save that as ie qemu.patch and run it with patch, but after trying a few combinations that failed as well.

In this context, what am I supposed to do with the above snippet?

2
  • It's hard to answer questions like this when you just say "fails". How did it fail? What did it tell you?
    – mattdm
    Sep 30, 2015 at 0:07
  • 2
    It would probably be easier to just open flatload.c and uncomment the line manually...
    – jasonwryan
    Sep 30, 2015 at 0:09

2 Answers 2

9

This is actually a very short diff command. It says to remove the line //#define DEBUG and replace it with #define DEBUG.

In this diff format, lines starting with a single - are removed and those with + are added. The other lines are for context, and the @@ tells the offset into the file and number of lines referenced. (And the triple +++ --- lines tell you which file was modified.)

The two common reasons for a patch to fail to apply are:

  1. The actual affected lines have changed, or
  2. The context around those lines has changed (possibly, changed too much, because patch usually uses a "fuzzy" algorithm.

In this case, it's probably easiest to look at the section of code by hand (in the linux-user/flatload.c file, as you can see from the first line), and see if there's a commented-out #define DEBUG anywhere, and then remove the // comment characters.

Looking at the code myself, I see that the problem is probably actually reason #3 — the patch is mangled because it's been rendered in a way it wasn't supposed to be. See that line that just says #include? In the original source, it says #include <target_flat.h>. The blog software where you found the patch probably decided that <target_flat.h> is a suspicious HTML tag and silently deleted it, and the author didn't notice.

2
  • I remember there being a flag to patch regarding the directory depth; perhaps that is throwing them off?
    – Jeff Schaller
    Sep 30, 2015 at 0:28
  • @JeffSchaller Ah, yes — -p0 or -p1 or whatever. Since I labeled something else as reason #3, that'll have to be reason #4. :)
    – mattdm
    Sep 30, 2015 at 0:30
2

This patch looks like it was created using git, specifically the git diff command. So you'd probably do well to use the git tools (specifically git apply) to patch it onto the target file(s):

git apply qemu.patch
1
  • 1
    Yeah, although in this case, that won't work because of the error in the patch.
    – mattdm
    Sep 30, 2015 at 22:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .