I thought of something while I didn't have access to my machine. There are two reasons why N-way merged files break.
Case 1: Mod A adds or deletes lines before mod B tries to change something. Mod B's changes end up in the wrong place, which may or may not cause issues.
Case 2: Mod A and mod B try to change the same line.
....
This should ensure that changes land where the modder thinks they will based on a vanilla diff. Won't ensure that the changes are compatible, but at least they won't be off in some other object.
Does that make sense to anyone other than me?
... Which is exactly why I'd go the route of Valdemar's stuff. First flatten everything,
then read/index all the objects/entities into structures,
then do the diff patch generation on an object by object basis. It's basically the same thing but with with the added bonus of the program being able to say explicitly what objects were deleted, what's been added and so on. You have two levels of differences - the objects present difference, and the difference between equatable objects themselves. The process to resolve conflicts becomes much more mechanical then, rather than holding hands up and saying, "well, it doesn't work and we don't know why".
In case 1 you'd know that the added lines of B would at least be in the correct object, and if the program was smart it could drop those lines in right after the correct preceding line.
In case 2 you'd know in what object the conflict arose and could prompt the user with relevant information.
This way would make this basic stuff easier, and open the door for more advanced stuff like making connections throughout the raws to entirely remove problem objects. The two pass method Dirst suggests is essentially the same thing but done in a roundabout way.
The diff patch stuff is a good start and totally necessary, but IMO it'd be pointless to do this without going the route of interrogating the raws in a raw-language manner. PE said he was adverse to an "advanced mod loader", which I understand... But I feel this way is the minimum, not an advanced feature.